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. 洛谷P3246 [HNOI2016]序列 [莫队]

    传送门 思路 看到可离线.无修改.区间询问,相信一定可以想到莫队. 然而,莫队怎么转移是个大问题. 考虑\([l,r]\rightarrow[l,r+1]\)时答案会怎样变化?(左端点变化时同理) \ ...

  2. java移位运算符:<<(左移)、>>(带符号右移)和>>>(无符号右移)。

    1. 左移运算符 左移运算符<<使指定值的所有位都左移规定的次数. 1)它的通用格式如下所示: value << num num 指定要移位值value 移动的位数. 左移的规 ...

  3. js的页面传值cookie.session

    jquery的cookie: 读取所有的cookie: document.cookie: 读取单个cookie:$.cookie('cookiename'); 新增cookie: $.cookie(' ...

  4. swift 学习- 20 -- 错误处理

    // 错误处理 是响应错误以及 从错误中恢复的过程, Swift 提供了在运行时对 可恢复错误的 抛出, 捕获, 传递 和 操作的支持 // 某些操作无法保证总是执行完所有代码 或总是生层有用结果, ...

  5. fatal: refusing to merge unrelated histories

    Git 提交代码时遇到冲突了,所以 git pull 拉不下来远程代码.使用一下命令解决: git pull origin master --allow-unrelated-histories 然后解 ...

  6. Guideline 5.2.1 - Legal - Intellectual Property 解决方案

    最近在上架公司公司项目的时候遇到这个问题什么5.2.1 然后去了解发现最近不少人都遇到了这个问题.先说一下 我上架的APP是一个医疗的APP然后说需要什么医疗资质,估计是账号的公司资质不够吧.后面和苹 ...

  7. U盘权限不足,只读文件系统

    https://blog.csdn.net/baocheng_521/article/details/77161791 用第一种方式成功

  8. javaScript遍历对象、数组总结

        javaScript遍历对象总结 1.使用Object.keys()遍历 返回一个数组,包括对象自身的(不含继承的)所有可枚举属性(不含Symbol属性). var obj = {'0':'a ...

  9. Spring Security Filter执行顺序

    1.场景:先走框架过滤器,后走自定义过滤器 @Bean public FilterRegistrationBean resourceFilterRegistration() { FilterRegis ...

  10. loadrunner获取当前日期、明日日期、昨日日期

    DATE_NOW(现在的日期) TIME_NOW(现在的时间) ONE_DAY(一天的时间) ONE_HOUR(一小时的时间) ONE_MIN(一分钟的时间) 可以使用公式获取昨天明天,例如: DAT ...