其实根据(a+b)%d=(a%d+b%d)%d就可以做出来了。
以7为例
1%7=1 1%7=1
11%7=4 (10%7+1)%7=4
111%7=6 (4*10%7+1)%7=6
1111%7=5 (6*10%7+1)%7=5
11111%7=2 (5*10%7+1)%7=2
111111%7=0 (2*10%7+1)%7=0
输出6.
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10892 | Accepted: 6193 |
Description
Input
Output
Sample Input
3 7 9901
Sample Output
3 6 12
Source
1 //oimonster 2 #include<cstdio> 3 #include<cstdlib> 4 #include<iostream> 5 using namespace std; 6 int main(){ 7 int i,j,n; 8 bool f; 9 int s,t=0; 10 while(scanf("%d",&n)!=EOF){ 11 f=false; 12 t=s=1; 13 t=t%n; 14 while(t!=0){ 15 t=(t*10%n+1)%n; 16 s++; 17 } 18 printf("%d\n",s); 19 } 20 return 0; 21 }
原文:http://www.cnblogs.com/oimonster/p/4356109.html