| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1177 人关注过本帖
标题:ACM,超大数据处理,求大神讲解。
只看楼主 加入收藏
liyue6822532
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2016-2-28
结帖率:57.14%
收藏
已结贴  问题点数:20 回复次数:1 
ACM,超大数据处理,求大神讲解。
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
输入

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.)
输出

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

142857
142856
142858
01
0588235294117647

样例输出

142857 is cyclic
142856 is not cyclic
142858 is not cyclic
01 is not cyclic
0588235294117647 is cyclic
搜索更多相关主题的帖子: different following original sequence example 
2016-03-23 20:51
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:20 
程序代码:
#include <stdio.h>
#include <string.h>

int main( void )
{
    for( char s[61]; scanf("%s",s)==1; )
    {
        int carry=0, i;
        const size_t n = strlen(s);
        for( i=n>1?n-1:-1; i!=-1 && ((s[i]-'0')*(n+1)+carry)%10==9; --i )
            carry = ((s[i]-'0')*(n+1)+carry)/10;

        printf( "%s%s", s, i==-1&&carry==0?" is cyclic\n":" is not cyclic\n" );
    }
    return 0;
}
2016-03-24 12:08
快速回复:ACM,超大数据处理,求大神讲解。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017490 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved