【描述】
全运会就要开始了,笨笨想成为湖南地区的火炬手,经过层层选拔,最终到了最后一关,这一关给出了一个正整数n(N≤100000),求一个最小的正整数m,使得nxm的十进制表示形式中只含l和0。
【输入格式】一行一个数n
【输出格式】
输出一行,如果有解,输出最小的m,否则
输出“no solution”。
Sample input
12
Sample output
925
【解题思路】
用队列,每一次×10和×10+1扩展,就能保证扩展到所有的01串
c++里好像不能直接出现一个超过int的数字,,所以加了一个字符串转化
【代码】
#include<iostream>
#include<cstring>
#include<cstdio>
#define N 1000000000000000
using namespace std;
long long queue[10000000];
long long n,x,head,tail,ans;
char s[50];
int main(){
freopen("torch.in","r",stdin);
freopen("torch.out","w",stdout);
cin>>n;
head=0,tail=1;
queue[tail]=1;
while (head<tail){
++head;
x=queue[head%1000000];
if (x%n==0){
ans=x/n;
cout<<ans; return 0;
}
sprintf(s,"%I64d",x); int len=strlen(s);
if (len<19)
{queue[(++tail)%1000000]=x*10;queue[(++tail)%1000000]=x*10+1;}
}
printf("no solution");
}