poj 1426 Find The Multiple( bfs )

时间:2023-03-09 23:52:01
poj 1426 Find The Multiple( bfs )

题目:http://poj.org/problem?id=1426

题意:输入一个数,输出这个数的整数 倍,且只有0和1组成

程序里写错了一个数,结果一直MLE.……

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<iomanip>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
using namespace std; long long a;
void bfs()
{
queue<long long>q;
int i,j;
long long x=,pos;
q.push(x);
while(!q.empty())
{
pos=q.front();
q.pop();
for(i=; i<; i++)
{
x=pos*+i;
if(x%a==)
{
cout<<x<<endl;
return;
}
q.push(x);
}
}
}
int main()
{
int i,j;
while(cin>>a&&a)
{
if(a==)
{
cout<<""<<endl;
continue;
}
bfs();
}
return ;
}

还 有用同余模定理做的

(a*b)%n = (a%n *b%n)%n

(a+b)%n = (a%n +b%n)%n

地址:http://blog.csdn.net/lyy289065406/article/details/6647917