Uniform Generator

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

Total Submission(s): 24381    Accepted Submission(s): 9642

Problem Description
Computer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form



seed(x+1) = [seed(x) + STEP] % MOD



where '%' is the modulus operator. 



Such a function will generate pseudo-random numbers (seed) between 0 and MOD-1. One problem with functions of this form is that they will always generate the same pattern over and over. In order to minimize this effect, selecting the STEP and MOD values carefully
can result in a uniform distribution of all values between (and including) 0 and MOD-1. 



For example, if STEP = 3 and MOD = 5, the function will generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a repeating cycle. In this example, all of the numbers between and including 0 and MOD-1 will be generated every MOD iterations of the function.
Note that by the nature of the function to generate the same seed(x+1) every time seed(x) occurs means that if a function will generate all the numbers between 0 and MOD-1, it will generate pseudo-random numbers uniformly with every MOD iterations. 



If STEP = 15 and MOD = 20, the function generates the series 0, 15, 10, 5 (or any other repeating series if the initial seed is other than 0). This is a poor selection of STEP and MOD because no initial seed will generate all of the numbers from 0 and MOD-1. 



Your program will determine if choices of STEP and MOD will generate a uniform distribution of pseudo-random numbers. 
 
Input
Each line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).
 
Output
For each line of input, your program should print the STEP value right- justified in columns 1 through 10, the MOD value right-justified in columns 11 through 20 and either "Good Choice" or "Bad Choice" left-justified starting in column 25. The "Good Choice"
message should be printed when the selection of STEP and MOD will generate all the numbers between and including 0 and MOD-1 when MOD numbers are generated. Otherwise, your program should print the message "Bad Choice". After each output test set, your program
should print exactly one blank line.
 
Sample Input
3 5
15 20
63923 99999
 
Sample Output
3 5 Good Choice 15 20 Bad Choice 63923 99999 Good Choice
 
Source
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1019 1012 1020 1017 1015 
 

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方…

#include<stdio.h>
int gcd(int a,int b)
{
return gcd(b,a%b);
if(!b)return a;
}
int s,m;
int main()
{
{
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;
}

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 解题报告

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

  5. HDU 1014 Uniform Generator 欧几里得

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

  6. HDU 1014 Uniform Generator 题解

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

  7. hdu 1014 Uniform Generator 数论

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

  8. HDU 1014 Uniform Generator(最大公约数,周期循环)

    #include<iostream> #include <cstdio> #include <cstring> using namespace std; int m ...

  9. 1014 Uniform Generator ACM

    http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目的英文实在是太多了 ,搞不懂. 最后才知道是用公式seed(x+1) = [seed(x) + STE ...

随机推荐

  1. nexenta systemcallerror

    最近在试nexenta做iscsi,设置ip出现上面的错误 解决办法,先讲mtu设置为不周与原来的值,比如原来为1500,先设置成1501,就可以了,然后可以再改回来,也是没有问题的!

  2. weiphp---------图灵机器人存在的bug。

    1.很多人下载下来weiphp源码以后,配置好了图灵机器人却不能使用.原因是因为他源码里面存在一个小bug 上图红色框框内是他的源码,问题就出在这里. 修改方法: if($result ['code' ...

  3. 机器学习笔记:Gradient Descent

    机器学习笔记:Gradient Descent http://www.cnblogs.com/uchihaitachi/archive/2012/08/16/2642720.html

  4. something about css locating.

    CSS position:static:默认属性,静态定位relative:相对定位,相对于父元素的定位,需要配合top,left,right,bottom,z-index等属性absolute:绝对 ...

  5. ACM/ICPC竞赛

    ACM知识点分类   第一类:基础算法 (1) 基础算法:枚举,贪心,递归,分治,递推,构造,模拟 (2) 动态规划:背包问题,树形dp,状态压缩dp,单调性优化,插头dp (3) 搜索:dfs,bf ...

  6. 接口是否可继承接口? 抽像类是否可实现(implements)接口? 抽像类是否可继承实体类(concrete class)?

    接口是否可继承接口? 抽像类是否可实现(implements)接口? 抽像类是否可继承实体类(concrete class)? 1. 接口可以继承接口. 2. 抽像类可以实现(implements)接 ...

  7. linux第6天 流协议-粘包

    今天学习的主要是对第5天的加强. 比如服务器的多进程,点对点应用聊天程序.父进程子进程互发消息.等等. 流协议-粘包 一般TCP协议会出现粘包,粘包产生的原因一般为.TCP协议是流式传输,不会根据用户 ...

  8. ajax基本用法

    ajax能做到无刷新数据交互,给用户体验带来好处的同时也减小了服务器的压力,所以运用ajax能使网站性能更强劲.更吸引用户. 大型网站少不了注册页面,而大多数情况下我们不想让用户有相同的注册ID,所以 ...

  9. zw版【转发·台湾nvp系列例程】HALCON EquHistoImage(Delphi)

    zw版[转发·台湾nvp系列例程]HALCON EquHistoImage(Delphi) zw版[转发·台湾nvp系列例程]HALCON EquHistoImage(Delphi) (Delphi ...

  10. IIS、Asp.net 编译时的临时文件路径(转载)

    IIS上部署的ASP.NET站点都会在一个.Net Framework的特定目录下生成临时编译文件增加ASP.NET站点的访问性能,有时候需要手动去删除这些临时编译文件,特别是发布新版本代码到IIS后 ...