[字符串加倍操作,find函数,大整数乘法]循环数

循环数

题目描述

当一个N位的整数X满足下列条件时,称其为循环数:X与任意一个整数1≤Y ≤ N相乘时,都将产生一个X的“循环”。即:分别将这两个整数的第1位数字与最后1位数字连在一起,可以得到一个相同的数字循环;当然两个整数在该数字循环中的起始位置不同。例如,142857是一个循环数
142857 *1 = 142857
142857 *2 = 285714
142857 *3 = 428571
142857 *4 = 571428
142857 *5 = 714285
142857 *6 = 857142

关于输入

写一个程序判断一个整数是否是循环数。输入文件是一个整数序列,每个整数长度为2~60。注意:每个整数前面的零被看作是该整数的一部分,在计算N时要统计。例如“01”是一个2位的整数,而“1”是一个1位的整数。

关于输出

对每个输入整数,输出一行,说明该整数是否是循环数。

例子输入
142857
142856
142858
01
0588235294117647
例子输出
142857 is cyclic
142856 is not cyclic
142858 is not cyclic
01 is not cyclic
0588235294117647 is cyclic
代码实现
#include <bits/stdc++.h>
using namespace std;
string bigintcf(string s,int k){
    int len=s.size();
    int carry=0;
    for(int i=len-1;i>=0;i--){
        int temp=(s[i]-'0')*k+carry;
        carry=temp/10;
        s[i]=temp%10+'0';
    }
    return s+s;
}
bool iscyclic(string s){
    int N=s.size();
    for(int i=1;i<=N;i++){
        string t=bigintcf(s,i);
        if(t.find(s)==string::npos){
            return 0;
        }
    }
    return 1;
}
int main(){
    string s;
    while(cin>>s){
        if(iscyclic(s)){
            cout<<s<<" is cyclic"<<endl;
        }
        else{
            cout<<s<<" is not cyclic"<<endl;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值