1109 01 Multiple base time limit consisting of N: 1 sec Space limit: 131072 KB given a natural number n, find a M, make M > 0 and M is a multiple of N, and M's 10 binary representation contains only 0 or 1. The smallest m. For example: N = 4,m = 100. Input
Enter 1 number n. (1 <= N <= 10^6)
Output
Outputs the smallest m that meets the criteria.
Input example
4
Output example
100
The same as http://www.cnblogs.com/zzuli2sjy/p/5731745.html;
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <cmath>5#include <iostream>6#include <algorithm>7#include <map>8#include <queue>9#include <vector>Ten#include <Set> One using namespacestd; AtypedefLong LongLL; - BOOLflag[6000000]; - intans[ -]; the Set<int>que; - Set<int>:: iterator it; -typedefstructpp - { + intMoD; - intID; + intPre; A intDigit; at pp () - { -pre=-1; - } - } SS; -SS bns[1000000]; in intask[1000000]; - intcp[2000000]; to intBFsintNintm); + intMainvoid) - { the inti,j,k; * while(SCANF ("%d", &k)! =EOF) $ {Panax Notoginseng intN; - intm; the que.clear (); +cp[0] =0; CP [1] =1; An =2; theans[0]=cp[0]; + intuu=cp[0]; - intt=1; $ for(i=1; i<n;i++) $ { - if(cp[i]!=UU) - { theans[t++]=Cp[i]; -uu=Cp[i];Wuyi } the } - Wu if(k==0) printf ("0\n"); - Else About { $ intsum=0; - intId=BFS (t,k); - if(id==-1) - { Aprintf"0\n"); + } the Else - { $ while(id!=-1) the { theask[sum++]=Bns[id].digit; theId=Bns[id].pre; the } - for(i=sum-1; i>=0; i--) in { theprintf"%d", Ask[i]); the } Aboutprintf"\ n"); the } the } the } + return 0; - } the intBFsintNintm)Bayi { the inti,j,k; the intkk=0; -memset (Flag,0,sizeof(flag)); -Queue<ss>STC; the for(i=0; i<n; i++) the { the intmod=ans[i]%m; the if(!flag[mod]&&ans[i]!=0) - { theflag[mod]=true; theBns[kk].id=KK; theBns[kk].mod=MoD;94bns[kk].pre=-1; thebns[kk].digit=Ans[i]; the Stc.push (Bns[kk]); thekk++;98 } About } - while(!stc.empty ())101 {102SS tt=Stc.front ();103 Stc.pop ();104 for(i=0; i<n; i++) the {106 intMod= (tt.mod*Ten+ans[i])%m;107 if(!Flag[mod])108 {109Bns[kk].id=KK; theBns[kk].pre=tt.id;111Bns[kk].mod=MoD; thebns[kk].digit=Ans[i];113 if(mod==0) the { the returnKK; the }117 Stc.push (Bns[kk]);118kk++;119flag[mod]=true; - }121 }122 }123 return-1;124}
1109 a multiple of 01 consisting of N