ZOJ 1073 Round and Round We Go

本文介绍了一种特殊的整数——循环数,并提供了一个程序实例来判断任意长度(2到60位)的整数是否为循环数。循环数的特征在于其乘以1至位数的任意整数时,产生的新数的数字序列与原数相同,只是起始位置不同。文章通过示例解释了这一概念,并给出了解决方案。
摘要由CSDN通过智能技术生成
Round and Round We Go

Time Limit: 2 Seconds       Memory Limit: 65536 KB

Problem

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:

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.


Example

Input


142857
142856
142858
01
0588235294117647

Output

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


题意:判断数是不是cyclic数,规律就是每个数乘上它的位数加1,每一位上都是9就是cyclic数


代码:

#include <stdio.h>
#include <string.h>


int main()
{
    char str[80];
    int a[80];
    while(scanf("%s",str)!=EOF)
    {
        int k,i,flag=0;
        k=strlen(str);
        a[k]=0;
        for(i=k-1;i>=0;i--)
        {
            int temp;
            temp=(k+1)*(str[i]-'0')+a[i+1];
            a[i]=temp/10;
            if(temp%10!=9)
            {
                flag=1;
                break;
            }
        }
        if(flag!=1)
            printf("%s is cyclic\n",str);
        else
            printf("%s is not cyclic\n",str);
        
    }
    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值