POJ 1047 Round and Round We Go

Round and Round We Go
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 11201   Accepted: 5181

Description

A cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a"cycle"of the digits of the original number. That is, if you consider the number after the last digit to "wrap around"back to the first digit, the sequence of digits in both numbers will be the same, though they may start at different positions.For example, the number 142857 is cyclic, as illustrated by the following table:  142857 *1 = 142857  142857 *2 = 285714  142857 *3 = 428571  142857 *4 = 571428  142857 *5 = 714285  142857 *6 = 857142 

Input

Write a program which will determine whether or not numbers are cyclic. The input file is a list of integers from 2 to 60 digits in length. (Note that preceding zeros should not be removed, they are considered part of the number and count in determining n. Thus, "01"is a two-digit number, distinct from "1" which is a one-digit number.)

Output

For each input integer, write a line in the output indicating whether or not it is cyclic.

Sample Input

142857
142856
142858
01
0588235294117647

Sample Output

142857 is cyclic
142856 is not cyclic
142858 is not cyclic
01 is not cyclic
0588235294117647 is cyclic

一道高精度乘法题
先把给定的数字可能转换成的各种数字形式都存储下来,之后开始验证,将每次乘得得结果与已经存好的数串进行比较,看看是否有一样的

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 
 5 using namespace std;
 6 
 7 int num[60][100],a[100];
 8 
 9 int main()
10 {
11     char temp[60];
12 
13     while(gets(temp))
14     {
15         int len=strlen(temp);
16         bool flag=true;
17         for(int i=0;i<len;i++)
18             num[0][len-i-1]=temp[i]-'0';
19         for(int i=len;i<100;i++)
20             num[0][i]=0;
21         for(int i=1;i<len;i++)
22             for(int j=0;j<len;j++)
23                 num[i][(j+i)%len]=num[0][j];
24         for(int i=1;i<=len;i++)
25         {
26             int j,c=0;
27             memset(a,0,sizeof(a));
28             for(j=0;j<100;j++)
29             {
30                 int s=num[0][j]*i+c;
31                 a[j]=s%10;
32                 c=s/10;
33             }
34             for(j=0;j<len;j++)
35             {
36                 int k;
37                 for(k=0;k<len;k++)
38                     if(num[j][k]!=a[k])
39                         break;
40                 if(k==len)
41                     break;
42             }
43             if(j==len)
44             {
45                 flag=false;
46                 break;
47             }
48         }
49         for(int i=len-1;i>=0;i--)
50             cout<<num[0][i];
51         if(flag)
52             cout<<" is cyclic"<<endl;
53         else
54             cout<<" is not cyclic"<<endl;
55     }
56 
57     return 0;
58 }
[C++]

 

posted @ 2013-05-30 18:39  ~~Snail~~  阅读(153)  评论(0编辑  收藏  举报