#include<iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void)
{
int s,m,i;
/*int seed=0;
int a[10005]={0};
//memset(a,0,sizeof(a));*/
while(scanf("%d%d",&s,&m)!=EOF);
{
int seed=0;
int a[10005]={0};
while(!a[seed])//
{
a[seed]=1;//若本位0,变换标志位为1,直到出现循环到头,标志过了的就跳出
seed=(seed+s)%m;//seed根据随机数公式变化
}
for(i=0;i<m;i++)//范围0-m
{
if(a[i]==0)//只要有没出现在0~m-1的数就不好
{
printf("%10d%10d Bad Choice\n\n",s,m);
break;
}
}
if(i==m){ //跳出循环后,刚好以m为周期
printf("%10d%10d Good Choice\n\n",s,m);
}
}
}

  

#include<iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int gcd(int a,int b)
{
if(a<b)
swap(a,b);
return b?gcd(b,a%b):a;
}
int main()
{
int i,j,s,m;
while(~scanf("%d%d",&s,&m))
{
if(gcd(s,m)==1)
{
printf("%10d%10d Good Choice\n\n",s,m);
}
else
{
printf("%10d%10d Bad Choice\n\n",s,m);
}
}
return 0;
}

  

#include <stdio.h>
#include <stdlib.h> int main()
{
int step,mod,seed,count;
while(scanf("%d%d",&step,&mod)!=EOF)
{
seed=0,count=1;
do
{
seed=(seed+step)%mod;
count++;
}while(seed!=0);
count--;
printf("%10d%10d ",step,mod);
if(count==mod)
printf("%s\n","Good Choice");
else
printf("%s\n","Bad Choice");
printf("\n");
}
system("pause");
return 0;
}

  

#include<iostream>
using namespace std; int main()
{
int s,m,x,c;
while(scanf("%d%d",&s,&m)!=EOF)
{
x=c=0;
do
{
x=(x+s)%m;
++c;
} while(x!=0); if(c==m)
printf("%10d%10d Good Choice\n\n",s,m);
else
printf("%10d%10d Bad Choice\n\n",s,m);
}
return 0;
}

  

HDU 1014 Uniform Generator(最大公约数,周期循环)的更多相关文章

  1. HDU 1014 Uniform Generator(模拟和公式)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java ...

  2. HDU 1014 Uniform Generator【GCD,水】

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. HDU 1014:Uniform Generator

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. HDU 1014 Uniform Generator(题解)

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. HDU 1014 Uniform Generator 欧几里得

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 解题思路: 1. 把题目意思读懂后,明白会输入两个数,然后根据题中的公式产生一系列伪随机数,看这 ...

  6. hdu 1014.Uniform Generator 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目意思:给出 STEP 和 MOD,然后根据这个公式:seed(x+1) = [seed(x) ...

  7. HDOJ 1014 Uniform Generator(公约数问题)

    Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...

  8. HDU 1014 Uniform Generator 题解

    找到规律之后本题就是水题了.只是找规律也不太easy的.证明这个规律成立更加不easy. 本题就是求step和mod假设GCD(最大公约数位1)那么就是Good Choice,否则为Bad Choic ...

  9. hdu 1014 Uniform Generator 数论

    摘取于http://blog.csdn.net/kenden23/article/details/37519883: 找到规律之后本题就是水题了,不过找规律也不太容易的,证明这个规律成立更加不容易. ...

随机推荐

  1. 为Ubuntu安装FTP服务

    打开"终端窗口",输入"sudo apt-get update"-->回车-->"输入当前登录用户的管理员密码"-->回车 ...

  2. 服务器下面的WEB-INF 不能直接访问,可以通过servlet进行访问

    服务器下面的WEB-INF 不能直接访问,可以通过servlet进行访问

  3. jquery/js iframe 元素操作

    1.判断id/ class 是否存在? <script> $(function(){ if(("#id_name").length()>0){ //如果id 存在 ...

  4. 二分查找 Binaryserach

    二分查找: 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表.首先,假设表中元素是按升 ...

  5. 洛谷P4589 [TJOI2018]智力竞赛 【floyd + 二分 + KM】

    题目链接 洛谷P4589 题意可能不清,就是给出一个带权有向图,选出\(n + 1\)条链,问能否全部点覆盖,如果不能,问不能覆盖的点权最小值最大是多少 题解 如果要问全部覆盖,就是经典的可重点的DA ...

  6. POJ3169:Layout(差分约束)

    Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15705   Accepted: 7551 题目链接:http ...

  7. gitlab7.2安装

    系统:centos6.4 1.安装依赖包 导入epel: useradd git wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-rel ...

  8. SQL优化单表案例

    数据准备: -- 创建数据库 mysql> create database db_index_case; Query OK, row affected (0.00 sec) -- 查看数据库 m ...

  9. Spring学习--通过注解配置 Bean (三)

    组件装配: <context:component-sacan> 元素还会自动注册 AutowiredAnnotationBeanPostProcesser 实例 , 该实例可以自动装配具有 ...

  10. Java节假日算法

    类:Vacation package test; import java.io.Serializable; import java.util.Date; public class Vacation i ...