生成的算法计算,用 C 语言来解答Uniform Generator

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
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

1
灰色直方图的一个问题,采用C语言计算每个值的分布的表示,怎么实现
1
C语言程序设计解决Pipe Fitters的算法问题的正确思路怎么实现
1
物体碰撞和反弹消除的判断,采用C语言解决这个算法怎么实现思路
1
一个圆形的管道的堆放的算法问题,怎么用C语言的办法解决呢
0
均匀的随机数的生成算子的实现,利用C语言的程序的编写的技术怎么实现
0
根据屏幕上的像素做计算的问题,怎么采用C语言的程序的设计的方式来实现的呢?
0
图的步数的一个计算的问题,怎么利用C语言的程序的设计的思想去实现的?
0
弹球游戏的一个算法试题,怎么利用C程序的语言的代码编写的步骤去实现的呢?
1
如何把c语言转化成java语言?
0
计算时间间隔的一个算法的求解问题,怎么利用C语言的程序代码编写的方式实现这个程序的计算的?
0
弹球的碰撞的计算的问题求出时间间隔,用C语言的程序的代码的编写的过程去实现的方式是什么
0
根据公式产生随机数矩阵,怎么使用C语言的程序代码编写的过程有效的实现这个问题的算法的
0
确定STEP和MOD的选择是否会产生伪随机数的均匀分布,用C语言的程序的设计的思想方式来实现的做法
0
计算以最小化离开迷宫的预期步数,怎么才能采用C语言的程序的设计的代码的编写的过程的设计的实现的原理
0
字符串按照url地址的规则编码的问题,是怎么采用C语言的程序的格式的做法来正确地实现的
0
特定降雨期间降雨量有多少根据给定的假设,怎么使用C语言的程序的编写的过程的代码有效地加以实现的
0
能在多长时间内驾驭HeavenHelix的预测,采用C语言的程序的编写的有效的设计的方式是什么
0
编写一个可以对一串字符进行百分比编码的程序用C语言的程序的设计怎么来编写的呢
0
一个Jezzball游戏的算法,怎么实现的用的C语言
0
降雨量的一个计算的问题,怎么采用C语言的计算实现的