Time Limit: 1000MS | Memory Limit: 10000K | |||
Total Submissions: 23557 | Accepted: 9723 | Special Judge |
Description
Input
Output
Sample Input
2 6 19 0
Sample Output
10 100100100100100100 111111111111111111
Source
题目大意:有多组数据,每组输入一个数,假设输入的数字为a,题目让你求一个数b, 这个数字b必须满足两个条件:(1) b%a=0 ( 2)数字b的每个位上的数字必须是0或者1, 个人比较喜欢BFS,其实这道题用深搜也挺方便。下面是我的bfs代码,数据比较大,定义long long类型
上代码:
#include <iostream>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
int n,flag;
void bfs(LL x)
{
LL s;
int i;
queue<LL>q;
while(!q.empty())
q.pop();
q.push(x);
while(!q.empty())
{
LL xx=q.front();
q.pop();
if(xx%n==0)
{
cout<<xx<<endl;
return;
}
for(i=0; i<=1; i++)
{
if(i==0)
{
s=xx*10;
}
else s=xx*10+1;
q.push(s);
}
}
}
int main()
{
while(cin>>n&&n)
{
bfs(1);
}
return 0;
}