Problem Description
A cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a ~{!0~}cycle~{!1~} of the digits of the original number. That is, if you consider the number after the last digit to ~{!0~}wrap around~{!1~} 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, ~{!0~}01~{!1~} is a two-digit number, distinct from ~{!0~}1~{!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

142857
142856
142858
01
0588235294117647
 

Sample Output

142857 is cyclic
142856 is not cyclic
142858 is not cyclic
01 is not cyclic
0588235294117647 is cyclic
 
题意:给你一个字符串,让你判断它是不是一个“循环串”,循环串的定义是这个字符串所对应的整数乘上1~n(它的长度)的任何一个数,所得的结果为这个字符串循环后所得的整数。
思路:因为长度最多只有60,所以直接模拟就行了,附上大数乘法模板。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double ldb;
#define inf 99999999
#define pi acos(-1.0)
#define eps 1e-15
#define maxn 200
#define Len 3000//大数的长度
using namespace std;
int len;
char a[Len],b[Len],c[Len];
void Mul(char a[],char b[],char c[])//大数乘法
{
int i,j,alen,blen,clen;
for(i=0; i<Len;i++){
c[i]='0';
}
c[Len]='\0';
alen=strlen(a);
blen=strlen(b);
reverse(a,a+alen);
reverse(b,b+blen);
int sum=0;
for(i=0; i<alen; i++){
for(j=0; j<blen; j++){
sum+=c[i+j]-'0'+(a[i]-'0')*(b[j]-'0');
c[i+j]=(sum%10)+'0';
sum/=10;
}
while(sum){
c[i+j++]+=sum%10;
sum/=10;
}
}
clen=len;
c[clen]='\0';
reverse(c,c+clen); }
char str[700],str1[700],str2[700];
struct node{
char s[70];
}d[70];
bool cmp(node a,node b){
return strcmp(a.s,b.s)<0;
} int main()
{
int n,m,i,j,tot,alen,blen;
while(scanf("%s",str1)!=EOF)
{
len=strlen(str1);
for(i=0;i<len;i++){
str[i]=str1[i];
str[i+len]=str1[i];
}
str[2*len]='\0';
for(i=1;i<=len;i++){
tot=i-1;
for(j=0;j<len;j++){
d[i].s[j]=str[tot];tot++;
}
d[i].s[len]='\0';
}
sort(d+1,d+1+len,cmp); int flag=1;
for(i=2;i<=len;i++){
alen=len;
for(j=0;j<len;j++){
a[j]=str[j];
}
a[alen]='\0'; int tt=i;
blen=0;
while(tt){
b[blen++]=tt%10+'0';
tt/=10;
}
b[blen]='\0';
reverse(b,b+blen);
Mul(a,b,c);
if(strcmp(c,d[i].s)!=0){
flag=0;
}
}
if(flag)printf("%s is cyclic\n",str1);
else printf("%s is not cyclic\n",str1);
}
}

hdu1313 Round and Round We Go (大数乘法)的更多相关文章

  1. POJ1047 Round and Round We Go

    题目来源:http://poj.org/problem?id=1047 题目大意: 有一些整数具有这样的性质:它的位数为n,把它和1到n的任意一个整数相乘结果的数字会是原数字的一个“环”.说起来比较抽 ...

  2. POJ 1047 Round and Round We Go 最详细的解题报告

    题目链接:Round and Round We Go 解题思路:用程序实现一个乘法功能,将给定的字符串依次做旋转,然后进行比较.由于题目比较简单,所以不做过多的详解. 具体算法(java版,可以直接A ...

  3. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  4. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  5. 用分治法实现大数乘法,加法,减法(java实现)

    大数乘法即多项式乘法问题,求A(x)与B(x)的乘积C(x),朴素解法的复杂度O(n^2),基本思想是把多项式A(x)与B(x)写成 A(x)=a*x^m+b B(x)=c*x^m+d 其中a,b,c ...

  6. HDOJ-1042 N!(大数乘法)

    http://acm.hdu.edu.cn/showproblem.php?pid=1042 题意清晰..简单明了开门见山的大数乘法.. 10000的阶乘有35000多位 数组有36000够了 # i ...

  7. 51 Nod 1027 大数乘法【Java大数乱搞】

    1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A,B的长度  ...

  8. 51 Nod 1028 大数乘法 V2【Java大数乱搞】

    1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A ...

  9. hdu_1042(模拟大数乘法)

    计算n! #include<cstring> #include<cstdio> using namespace std; ]; int main() { int n; whil ...

随机推荐

  1. Harbor镜像删除回收?只看这篇

    最近,公司的技术平台,运维的破事儿颇多.Jira无法访问,ES堆内存不足,Jenkins频繁不工作..等等等,让我这个刚入门的小兵抓心脑肝,夜不能寐,关键时刻方恨经验薄弱呀!!一波未平,一波又起,这不 ...

  2. 【JavaWeb】JSTL 标签库

    JSTL 标签库 简介 JSTL(JSP Standard Tag Library),即 JSP 标准标签库.标签库是为了替换代码脚本,使得整个 jsp 页面变得更加简洁. JSTL 有五个功能不同的 ...

  3. 使用OpenCV进行简单的人像分割与合成

    图像合成 实现思路 通过背景建模的方法,对源图像中的动态人物前景进行分割,再将目标图像作为背景,进行合成操作,获得一个可用的合成影像. 实现步骤如下. 使用BackgroundSubtractorMO ...

  4. memcached+magent的集群部署详细过程

    问题描述 Memcached在实现分布集群部署时, Memcached服务端的之间是没有通讯的,服务端是伪分布式,实现分布式是由客户端实现的,客户端实现了分布式算法把数据保存到不同的Memcached ...

  5. 【Linux】zabbix4.0服务器搭建,agent搭建,及邮件使用方法

    zabbix默认的 服务端监听端口为10051,而被监控端即Zabbix--agents代理程序监控10050端口. 更新yum源: yum clean all yum makecache 需要配置网 ...

  6. ctfhub技能树—RCE—过滤cat

    打开靶机 查看页面信息 构造payload 127.0.0.1 || ls 题目提示过滤了cat,但我还是想试试 果然不行 网页访问没有结果,应该和上题一样被注释了,使用和同样的方法进行解题 利用命令 ...

  7. Spring Boot Scheduled定时任务特性

    SpringBoot中的Scheduled定时任务是Spring Boot中非常常用的特性,用来执行一些比如日切或者日终对账这种定时任务 下面说说使用时要注意的Scheduled的几个特性 Sched ...

  8. 力软最新版本与.netCore版本

    功能强大,直接上图: 加微信或QQ交流开发技术:25489181 netcore版本 版本优势: .NET Core是适用于 Windows.Linux 和 macOS 的免费.开源托管的计算机软件框 ...

  9. Docker下梦织CMS的部署

    摘要:Docker的广泛应用相对于传统的虚拟机而言提高了资源的利用率,推广后docker的影响不容忽视,在启动速度.硬盘.内存.运行密度.性能.隔离性和迁移性方面都有很大的提高.本次实训我们在cent ...

  10. 琐碎的想法(三)对Java的批评的看法

    编写本文的目的 在大环境下,Java是一个饱受争议的语言,一方面在工程上它的流行程度非常高:另一方面,越是资深的软件工程师就越容易对这个语言感到不满. 在这种情况下,博主希望每一个Java程序员能够耐 ...