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.

InputEach line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000). 
OutputFor 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

思路  : 水了两晚上的题,差点淹死.......这个题有两种做法,首先就是普通做法,其次就是求两个数最大公约数是不是一;

第一种方法:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int s,mod,i;
while(~scanf("%d%d",&s,&mod))
{
int a[100001] = {0},seed=0;
while(!a[seed]){
a[seed] = 1;
seed = (seed+s)%mod;
}
for(i=0;i<mod;i++){
if(a[i] == 0){
printf("%10d%10d Bad Choice\n\n",s,mod);break;
}
}
if(i==mod){
printf("%10d%10d Good Choice\n\n",s,mod);
}
}
return 0;
}

  

第二种方法

#include <bits/stdc++.h>
using namespace std;
int main()
{
int step,mod1,t;
while(scanf("%d%d",&step,&mod1)==2)
{
printf("%10d%10d",step,mod1);
while(mod1)
{
t = step%mod1;
step = mod1;
mod1 = t;
}
printf(" %s\n\n",step == 1? "Good Choice":"Bad Choice");
}
return 0;
}

  欢迎批评指正。

Uniform Generator的更多相关文章

  1. HDU 1014:Uniform Generator

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

  2. Uniform Generator 分类: HDU 2015-06-19 23:26 11人阅读 评论(0) 收藏

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

  3. uva 408 Uniform Generator

    Uniform Generator  Computer simulations often require random numbers. One way to generate pseudo-ran ...

  4. HDU 1014 Uniform Generator【GCD,水】

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

  5. HDU 1014 Uniform Generator(题解)

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

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

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

  7. (杭电 1014)Uniform Generator

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

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

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

  9. 1014 Uniform Generator

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

随机推荐

  1. 分布式系统的一致性协议之 2PC 和 3PC

    在分布式系统领域,有一个理论,对于分布式系统的设计影响非常大,那就是 CAP 理论,即对于一个分布式系统而言,它是无法同时满足 Consistency(强一致性).Availability(可用性) ...

  2. 练就Java24章真经—你所不知道的工厂方法

    前言 最近一直在Java方向奋斗<终于,我还是下决心学Java后台了>,今天抽空开始学习Java的设计模式了.计划有时间就去学习,你这么有时间,还不来一起上车吗? 之所以要学习Java模式 ...

  3. deepin、Ubuntu安装Nginx

    deepin安装nginx 切换至root用户 su 密码: 基础库的安装 安装gcc g++的依赖库 sudo apt-get install build-essential && ...

  4. ionic3 国际化

    http://www.cnblogs.com/huangenai/p/6868173.html 按上面这个网站的步骤整一遍, 但是ionic3 会报错  所以 在 import { NgModule ...

  5. 步步为营-84-数字转化为金额的Js+enter键取消页面刷新

    说明:来不及细说了,老铁快上车 function fmoney(s, n) { console.log(s); n = n > && n <= ? n : ; s = pa ...

  6. Command 'ifconfig' not found, but can be installed with: sudo apt install net-tools

    然后按照错误信息安安装网络工具: sudo apt install net-tools shl@shl-tx:~$ sudo apt install net-tools正在读取软件包列表... 完成正 ...

  7. Reading Refs

    有时候看论文时会有一种发现“新大陆”的感觉......也许这就是科研魅力之一!

  8. 将txt文本转换为excel格式

    将txt文本转换为excel格式,中间使用的列分割为 tab 键 一.使用xlwt模块 注:Excel 2003 一个工作表行数限制65536,列数限制256 需要模块:xlwt 模块安装:xlwt ...

  9. 解决notepad++64位没有plugin manager的问题

    安装了最新的notepad++版本发现没有插件管理器,很难受. 后来上官网发现了这样一句话 Note that the most of plugins (including Plugin Manage ...

  10. IIS异常

    http 错误 500.19 - internal server error 今天发布wcf到本地的IIS上,访问时出现了500.19错误.有效解决办法:是因为IIS没有安装完全,把能勾选的全部勾选上 ...