POJ 1047
来源:互联网 发布:刺客信条4优化补丁 编辑:程序博客网 时间:2024/05/29 17:47
Round and Round We Go
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 13074 Accepted: 6116
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
Source
Greater New York 2001
题意: 给你一个数n(可有前导0),让你判断是否
分析: 我们可以先把n的所有循环数预处理出来,然后与乘积后的数进行暴力对比即可
参考代码
import java.util.ArrayList;import java.util.Arrays;import java.util.Scanner;import java.math.BigInteger;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<String> res = new ArrayList<String>(); String s; while (in.hasNext()) { res.clear(); s = in.next(); int len = s.length(); for(int i = 0;i < len;i++) { String ss = s.substring(i,len) + s.substring(0,i); res.add(ss); } BigInteger a = new BigInteger(s); boolean tag = false; for(int i = 1;i <= len;i++) { BigInteger b = a.multiply(BigInteger.valueOf(i)); String ss = b.toString(); while (ss.length() < len) { ss = '0' + ss; } boolean flg = false; for(int j = 0;j < len;j++) { if(res.get(j).compareTo(ss) == 0) { flg = true; break; } } if(!flg) { tag = true; break; } } if(!tag) { System.out.println(s+" is cyclic"); } else { System.out.println(s+" is not cyclic"); } } }}
- 如有错误或遗漏,请私聊下UP,thx
- POJ 1047
- poj 1047
- poj 1047
- POJ 1047
- POJ 1047
- POJ 1047
- POJ ACM 1047
- poj 1045,1047
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- HTML:HTML基本标记
- 手写事件模型及事件代理/委托
- linux系统使用之本地yum源搭建
- 大数斐波那契【矩阵快速幂】
- [arc063e]Integers on a Tree
- POJ 1047
- (kruskal最小生成树)数据结构实验之图论六:村村通公路
- 创建一个Git项目并且发布到Github
- Set Similarity
- C语言操作符
- 前端之wordpress
- 机器学习的本质就是数理统计?答案可能没这么简单
- applicationContext.xml里面抽取spring data jpa之后报错
- Menu菜单的使用