博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1047
阅读量:6160 次
发布时间:2019-06-21

本文共 2632 字,大约阅读时间需要 8 分钟。

Round and Round We Go
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 10514   Accepted: 4812

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

142857142856142858010588235294117647

Sample Output

142857 is cyclic142856 is not cyclic142858 is not cyclic01 is not cyclic0588235294117647 is cyclic
#include 
#include
#include
using namespace std;const int N = 65;char str[N];int num[N],ans[N],len;int cmp(const void *a,const void *b){ return *(int *)a-*(int *)b;}bool is_match(){ qsort(num,len,sizeof(int),cmp); qsort(ans,len,sizeof(int),cmp); int i; for(i=0;i
=0;i--) num[j++]=str[i]-'0'; for(i=2;i<=len;i++) { memset(ans,0,sizeof(ans)); for(j=0;j
9) { ans[k+1] += ans[k]/10;//两条语句不可交换,搞了好久才发现 ans[k] %= 10; } } bool flag = is_match(); if(flag) { if(i==len) { for(j=0;j
=0;j--) num[k++]=str[j]-'0'; } else { for(j=0;j
 
对于数N,若N为循环的则有N*(length(N)+1)=99....99, (length(N)个9),length(N)为N的位数,含前导0。应该还是简单的...   
//此为转载
#include<iostream>
#include<string>
using
namespace
std;
bool
fun(string str)
{
   
int
n=str.length()+1;
   
int
i,up=0,temp=0;
   
for
(i=n-2;i>=0;i--)
   
{
       
temp=(
int
)(str[i]-
'0'
);
       
if
((temp*n+up)%10!=9)
return
false
;
       
up=(temp*n+up)/10;
   
}
   
return
true
;
}
int
main()
{
   
string str1;
   
while
(cin>>str1)
   
{
       
if
(fun(str1))
       
{
           
cout<<str1<<
" is cyclic"
<<endl;
       
}
       
else
       
{
           
cout<<str1<<
" is not cyclic"
<<endl;
       
}
   
}
   
return
0;
}

  

 
你可能感兴趣的文章
Linux 查看iptables状态-重启
查看>>
amazeui学习笔记一(开始使用2)--布局示例layouts
查看>>
c#中lock的使用(用于预约超出限额的流程)
查看>>
ODI基于源表时间戳字段获取增量数据
查看>>
并发容器之CopyOnWriteArrayList(转载)
查看>>
什么是AAC音频格式 AAC-LC 和 AAC-HE的区别是什么
查看>>
原创:goldengate从11.2升级到12.1.2
查看>>
Quartz
查看>>
正则表达式的语法规则
查看>>
C#一个关于委托和事件通俗易懂的例子
查看>>
类似于SVN的文档内容差异对比工具winmerge
查看>>
Cause: java.sql.SQLException: The user specified as a definer ('root'@'%') does not exist
查看>>
quratz线程
查看>>
execnet: rapid multi-Python deployment
查看>>
windows修改3389端口
查看>>
关于JavaScript词法
查看>>
FreeSwitch中的会议功能(4)
查看>>
MySQL中创建用户分配权限(到指定数据库或者指定数据库表中)
查看>>
AutoReleasePool 和 ARC 以及Garbage Collection
查看>>
重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础
查看>>