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. 【JavaWeb】Filter 过滤器

    Filter 过滤器 简介 Filter 过滤器是 JavaWeb 三大组件之一 Filter 过滤器是 JavaEE 的规范,也就是接口 Filter 过滤器的作用是 拦截请求,过滤响应 拦截请求的 ...

  2. LeetCode235 二叉搜索树的最近公共祖先

    给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:"对于有根树 T 的两个结点 p.q,最近公共祖先表示为一个结点 x,满足 x 是 p.q 的祖 ...

  3. 阿里面试官:什么是MySQL索引,为什么要有索引?

    一.什么是索引? 索引就好比字典的目录一样 我们通常都会先去目录查找关键偏旁或者字母再去查找 要比直接翻查字典查询要快很多 二.为什么要有索引? 然而我们在使用mysql数据库的时候也像字典一样有索引 ...

  4. linux下的文件类型

    在Linux中一切设备皆文件,首先来看一下Linux下的文件都有哪些分类,也就是文件类型 文件类型:普通文件(包括shell脚本,文档,音频,视频).目录文件.设备文件(又细分为字符设备文件和块设备文 ...

  5. Python实验6--网络编程

    题目1 1.编写程序实现基于多线程的TCP客户机/服务器程序. (1)创建服务器端套接字Socket,监听客户端的连接请求: (2)创建客户端套接字Socket,向服务器端发起连接: 服务器端套接字 ...

  6. Linux下Too many open files问题排查与解决

    作者: Grey 原文地址: Github 语雀 博客园 Too many open files是Linux系统中常见的错误,从字面意思上看就是说程序打开的文件数过多,不过这里的files不单是文件的 ...

  7. Objects as Points:预测目标中心,无需NMS等后处理操作 | CVPR 2019

    论文基于关键点预测网络提出CenterNet算法,将检测目标视为关键点,先找到目标的中心点,然后回归其尺寸.对比上一篇同名的CenterNet算法,本文的算法更简洁且性能足够强大,不需要NMS等后处理 ...

  8. CMU数据库(15-445)-实验2-B+树索引实现(中)删除

    3. Delete 实现 附上实验2的第一部分 https://www.cnblogs.com/JayL-zxl/p/14324297.html 3. 1 删除算法原理 如果叶子结点中没有相应的key ...

  9. 从零搭建一个IdentityServer——项目搭建

    本篇文章是基于ASP.NET CORE 5.0以及IdentityServer4的IdentityServer搭建,为什么要从零搭建呢?IdentityServer4本身就有很多模板可以直接生成一个可 ...

  10. Bitter.Core系列四:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之 示例 查询

    一: 单表模型驱动查询 如下示例代码演示: // 根据ID 查询: var studentquery = db.FindQuery<TStudentInfo>().QueryById(12 ...