# Round and Round We Go POJ 1047

JWMNEU · · 1158 次点击 · · 开始浏览

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```
`做这个题的时候想法很简单，最笨的办法，直接遍历，但是不知道为什么WA了，求探讨。同时在和人探讨的过程中，也学到了一个新的解法：`

###### ```#include<iostream> #include<string> #include<map> using namespace std; map<string, int> dic; string sline; void init(){ string str[8] = {"142857","0588235294117647","052631578947368421","0434782608695652173913","0344827586206896551724137931", "0212765957446808510638297872340425531914893617","0169491525423728813559322033898305084745762711864406779661", "016393442622950819672131147540983606557377049180327868852459"}; for(int i=0;i<8;i++) dic[str[i]]=1; } int main(){ init(); while(cin>>sline){ if(dic.count(sline)==1) cout<<sline<<" is cyclic"<<endl; else cout<<sline<<" is not cyclic"<<endl; } }```

0 回复

• 请尽量让自己的回复能够对别人有帮助
• 支持 Markdown 格式, **粗体**、~~删除线~~、``单行代码``
• 支持 @ 本站用户；支持表情（输入 : 提示），见 Emoji cheat sheet
• 图片支持拖拽、截图粘贴等方式上传

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```
`做这个题的时候想法很简单，最笨的办法，直接遍历，但是不知道为什么WA了，求探讨。同时在和人探讨的过程中，也学到了一个新的解法：`