您的位置:首页 > 其它

poj1426

2016-03-16 18:47 204 查看
//poj  1426
//看了老半天用有道也没弄明白什么意思,可能是做的题太少了
//题干中
/*
题目:
Given a positive integer n, write a program to find out a nonzero
(multiple  ---  是倍数的意思!!!)
multiple m of n whose decimal representation contains only the digits 0 and 1.
*/
//BFS...
//天..我刚刚明白题意..是指作为二进制的m  是n的倍数  即  2-10   10可以整除2
#include<iostream>
using namespace std;
int a[524300],i,n;
int main()
{
while(cin>>n)
{
if (!n) break;
i=1;
a[1]=1%n;
while(a[i])
{
i++;
a[i]=(a[i/2]*10+i%2)%n;
}
n=0;
while(i)
{
a[n++]=i%2;
i>>=1;   //位运算,右移表示除以2,速度较快一点
}
while(n--) cout<<a
;  //用cout打代码速度应该会快一点,还不用考虑数据类型
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: