poj 3652 Persistent Bits

#include <iostream>
using namespace std;
int bin[16];
bool visited[70000];
int main()
{
int a,b,c,s,temp,i;
while(cin>>a&&a)
{
cin
>>b>>c>>s;
memset(bin,
0,sizeof(bin));
memset(visited,
0,sizeof(visited));
visited[s]
=1;
i
=15;temp=s;
while(temp)
{
bin[i
--]=temp%2;
temp
/=2;
}
s
=(a*s+b)%c;
while(visited[s]==0)
{
visited[s]
=1;
i
=15;temp=s;
while(temp)
{
if(bin[i]!=temp%2)
bin[i]
=2;
temp
/=2;
i
--;
}
s
=(a*s+b)%c;
}
for(int i=0;i<16;++i)
if(bin[i]==2)
printf(
"?");
else
printf(
"%d",bin[i]);
printf(
"\n");
}
return 0;
}

  

posted on 2011-07-22 16:51  sysu_mjc  阅读(101)  评论(0编辑  收藏  举报

导航