Round and Round We Go

本文介绍了一个用于判断特定整数是否为循环数的程序实现。循环数是指一个整数,当它乘以从1到其位数长度之间的任意整数时,结果会形成原始数字的循环序列。文章详细解释了循环数的概念,并提供了一段C++代码,该代码通过检查每一位乘以(循环数的位数+1)的余数是否都是9来确定输入数字是否为循环数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



Description

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

循环数的每一位乘以(循环数的位数+1)余数都是9来判断

#include <iostream>
#include <cstring>
using namespace std;
char c[100];
int main()
{
	memset(c,'\0',sizeof(c));
	while(cin>>c)
	{
		int len,w=0,temp;
		len=strlen(c);
		for(int i=len-1;i>=0;i--)
		{
			temp=(int)(c[i]-'0')*(len+1)+w;
			if(temp%10!=9)
			{
				cout<<c<<" is not cyclic"<<endl;
				break;
			}
			w=temp/10;
			if(i==0)
				cout<<c<<" is cyclic"<<endl;
		}
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值