HOJ 1108
题目链接:HOJ-1108
题意为给定N和M,找出最小的K,使得K个N组成的数能被M整除。比如对于n=2,m=11,则k=2.
思路是抽屉原理,K个N组成的数modM的值最多只有M个。
具体看代码:
1 #include"cstdio" 2 #include"iostream" 3 #include"cstring" 4 #include"algorithm" 5 #include"cstdlib" 6 #include"vector" 7 #include"set" 8 #include"map" 9 #include"cmath" 10 using namespace std; 11 typedef long long LL; 12 const LL MAXN=10010; 13 14 int vis[MAXN]; 15 int main() 16 { 17 #ifdef LOCAL 18 freopen("in.txt","r",stdin); 19 // freopen("out.txt","w",stdout); 20 #endif 21 int n,m; 22 while(scanf("%d%d",&n,&m)==2) 23 { 24 memset(vis,0,sizeof(vis)); 25 int tmp=0,ans=0; 26 for(int i=1;i<=m;i++) 27 { 28 ans++; 29 tmp=(tmp*10+n)%m; 30 vis[tmp]=1; 31 if(tmp==0) break; 32 } 33 if(vis[0]) printf("%d\n",ans); 34 else printf("0\n"); 35 } 36 return 0; 37 }