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. Linux学习笔记 | docker基本命令

    Docker的三大核心概念:镜像.容器.仓库 镜像:类似虚拟机的镜像.用俗话说就是安装文件. 容器:类似一个轻量级的沙箱,容器是从镜像创建应用运行实例,可以将其启动.开始.停止.删除.而这些容器都是相 ...

  2. (二)数据源处理4-excel部分封装及数据转换

    excel02.py # -*- coding: utf-8 -*-#@File :excel_oper_02.py#@Auth : wwd#@Time : 2020/12/7 8:16 下午impo ...

  3. oracle查看用户的系统权限,角色以及数据库对象权限

    select * from dba_sys_privs where GRANTEE='monkey'; select * from dba_role_privs where GRANTEE='monk ...

  4. AQS之ReentrantReadWriteLock精讲分析上篇

    1.用法 1.1 定义一个安全的list集合 public class LockDemo { ArrayList<Integer> arrayList = new ArrayList< ...

  5. Nginx架构赏析

    淘宝的某位大佬曾经做过测试,在一台24G内存的机器上,Nginx的最大并发连接数达到了200万.同学们听到这个结论后,是不是被Nginx的超高性能深深折服了,它内部的架构设计究竟是怎么样的呢?这篇文章 ...

  6. python的零碎知识

    1.Python代码操作git 安装 pip3 install gitpython 操作git import os from git.repo import Repo # gitpython def ...

  7. Apache环境下强制http跳转至https的配置总结

    一. 简单实例介绍一般来说,apache配置好http和https后,如果想要做http强转到https,需要设置url重定向规则,大致需要下面几个步骤即可完成配置: 1)在httpd.conf文件里 ...

  8. Python+Selenium+Unittest实现PO模式web自动化框架(1)

    1.什么是PO模式? PO是Page Object的缩写 PO模式是自动化测试项目开发实践的最佳设计模式之一,讲页面定位和业务操作分开,也就是把对象的定位和测试脚本分开,从而提供可维护性. 主要有以下 ...

  9. libuv工作队列

    目录 1.说明 2.API 2.1.uv_queue_work 2.2.uv_cancel 3.代码示例 1.说明 libuv 提供了一个线程池,可用于运行用户代码,libuv 中的工作队列中的任务会 ...

  10.  打开APP  04 | 网络通信:RPC框架在网络通信上更倾向于哪种网络IO模型? 2020-02-26 何小锋

     打开APP  04 | 网络通信:RPC框架在网络通信上更倾向于哪种网络IO模型? 2020-02-26 何小锋