#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. [NOI2017 D1T1]整数

    题目大意:有一个整数 $x$ ,一开始为 $0$ .有 $n$ 个操作,有两种类型: $1 \;a\; b$:将 $x$ 加上整数 $a\cdot 2^b$ ,其中 $a$ 为一个整数, $b$ 为一 ...

  2. 获取Parameter参数值,方便调试使用

    #region #warning 调试使用,获取sql参数化,拼接出完整的sql语句,复制sql明文到mssql中运行 string debugSql = queryHelper.CommandTex ...

  3. Palindrome [Manecher]

    Palindrome Time Limit: 15000MS Memory Limit: 65536K Total Submissions: 12214 Accepted: 4583 Descript ...

  4. dbcp基本配置和重连配置

    转载自:http://agapple.iteye.com/blog/772507 最近在看一些dbcp的相关内容,顺便做一下记录,免得自己给忘记了. 1. 引入dbcp (选择1.4) Java代码  ...

  5. 前端导出文件功能document.execCommand命令

    参照 http://blog.csdn.net/woshinia/article/details/18664903

  6. SpringMVC——helloword入门

    参考 http://www.cnblogs.com/bigdataZJ/p/springmvc1.html 文章主要讲述以下内容: 搭建环境 静态请求拦截 动态请求拦截 补充: 1.Controlle ...

  7. PCIe 中的Capability 结构的寻址

    PCI-X 和PCIe 总线规范要求其设备必须支持Capabilities 结构.在PCI 总线的基本配置空间中,包含一个Capabilities Pointer 寄存器,该寄存器存放Capabili ...

  8. bzoj 3223 裸splay

    裸的splay 今儿写的splay,由于自己刚开始学,发现几个容易漏掉的地方 1:开始给所有的儿子赋值为-1 2:给max[-1]赋值为-maxlongint 3:开始father[root]:=sr ...

  9. 关于jQuery.extend

    这次来了解下jQuery的extend吧,作为菜鸟的我学艺不精,看插件时经常看到extend函数的使用,从网上看到一篇不错的介绍,特地转载过来留给自己收藏学习: ------------------- ...

  10. HDU1083(二分图最大匹配vector实现)

    Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...