Uniform Generator 

Computer simulations often require random numbers. One way to generatepseudo-random numbers is via a function of the form

where `` " is the modulus operator.

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

For example, if STEP = 3 and MOD = 5, the function will generate theseries of pseudo-random numbers 0, 3, 1, 4, 2 in a repeating cycle. In thisexample, all of the numbers between and including 0 and MOD-1 will begenerated every MOD iterations of the function. Note that by the natureof 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 andMOD-1, it will generate pseudo-random numbers uniformly withevery MOD iterations.

If STEP = 15 and MOD = 20, the function generates the series0, 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 seedwill generate all of the numbers from 0 and MOD-1.

Your program will determine if choices of STEP and MOD willgenerate a uniform distribution of pseudo-random numbers.

Input

Each line of input will contain a pair of integers for STEPand MOD in that order ( ).

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 incolumns 11 through 20 and either ``Good Choice" or ``Bad Choice"left-justified starting in column 25. The ``Good Choice" message shouldbe printed when the selection of STEP and MOD will generate allthe numbers between and including 0 and MOD-1 when MOD numbers aregenerated. 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

题意:根据给出的step和mod, 能否用题目中给的出的公式, 得到0到mod-1的余数

做法:要用线性同余方程, 其实也可以求是否两个数互质~

AC代码:
#include<stdio.h>

int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
} int main() {
int step, mod;
while(scanf("%d%d", &step, &mod) != EOF) {
printf("%10d%10d ", step, mod);
if(gcd(step, mod) == 1)
printf("Good Choice\n\n");
else
printf("Bad Choice\n\n");
}
return 0;
}

UVA 408 (13.07.28)的更多相关文章

  1. UVA 10392 (13.07.28)

    Problem F: Factoring Large Numbers One of the central ideas behind much cryptography is that factori ...

  2. UVA 568 (13.07.28)

     Just the Facts  The expression N!, read as `` N factorial," denotes the product of the first N ...

  3. UVA 299 (13.07.30)

     Train Swapping  At an old railway station, you may still encounter one of the lastremaining ``train ...

  4. UVA 140 (13.07.29)

     Bandwidth  Given a graph (V,E) where V is a set of nodes and E is a set of arcsin VxV, and anorderi ...

  5. 07-09 07:28:38.350: E/AndroidRuntime(1437): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.googleplay.ui.activity.MainActivity" on path: DexPathList[[zip file "/data/app/c

    一运行,加载mainActivity就报错 布局文件乱写一通,然后急着运行,报莫名其妙的错误: 07-09 07:28:38.350: E/AndroidRuntime(1437): Caused b ...

  6. Feb 5 13:07:52 plugh rsyslogd-2177: imuxsock begins to drop messages from pid 12105 due to rate-limiting

    FROM:https://www.nri-secure.co.jp/ncsirt/2013/0218.html SANSインターネットストームセンターのハンドラであるJohannes Ullrichが ...

  7. UVA 10194 (13.08.05)

    :W Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (ameri ...

  8. Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33

    06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie &q ...

  9. UVA 253 (13.08.06)

     Cube painting  We have a machine for painting cubes. It is supplied withthree different colors: blu ...

随机推荐

  1. 他们控制的定义--让背景颜色变化ViewPager逐步幻灯片

    转载请注明出处.谢谢~ 今天想说一个简单但很好的效果达到.代码是绝对简单,达到绝对easy,就是你可能想不到而已. 不多说,上效果图. 第一个效果是仿最美应用的滑动颜色变化,第二个是我项目中要用的效果 ...

  2. android_Activity生命周期功能

    说明:初步activity 生命周期7功能. 样本:于MainActivity我加了button,搬家button.跳到OtherActivity.控制台输出的观察. 让我们来看看这些功能: 他们的流 ...

  3. MVC中的Repository模式

    1.首先创建一个空的MVC3应用程序,命名为MyRepository.Web,解决方案命名为MyRepository. 2.添加一个类库项目,命名为MyRepository.DAL,添加一个文件夹命名 ...

  4. kobox : key_waitqueue.c -v1 如何内核线程,如何使用等待队列

    平台:TQ2440 按键驱动 (1)在init中创建一个内核线程作为等待队列的处理函数,该内核线程是一个while(1)死循环,一直检測等待队列的触发条件 DECLARE_WAIT_QUEUE_HEA ...

  5. 关于tasklet的一点小小的解释

    大概有一些同学对tasklet的串行化还有点困惑,其实在单处理器上最好理解,所以本帖主要讨论多处理器上tasklet如何实现串行化:同一个tasklet对象同一时刻只能在一个处理器上运行. 在 驱动程 ...

  6. PyCharm 使用简介

    PyCharm 使用简介 最近由于项目需要,领导要求使用python以方便扩展,没有办法,赶鸭子上架花了2天时间翻完了python的初级教程然后就开始写代码.有一款好的IDE可以帮助我快速上手一门新语 ...

  7. API帮助页面

    ASP.NET Web API 2:创建API帮助页面        当你新建了一个web API服务之后,再建一个API帮助页面是很有好处的,这样其他开发人员就会很清楚地知道如何调用你的API接口. ...

  8. PHP-微信公众平台开发-接收用户输入消息类型并响应

    原文:PHP-微信公众平台开发-接收用户输入消息类型并响应 <?php // 该代码块用于接收用户消息,根据用户输入的消息类型进行判断,文本,图片,视频,位置,链接,语音等,并取得值,处理后给予 ...

  9. 详解linux vi命令用法

    vi是所有UNIX系统都会提供的屏幕编辑器,它提供了一个视窗设备,通过它可以编辑文件.当然,对UNIX系统略有所知的人,或多或少都觉得vi超级难用,但vi是最基本的编辑器,所以希望读者能好好把它学起来 ...

  10. ARM指令集中经常使用的存储和载入指令

    ARM微处理器支持载入/存储指令用于在寄存器和存储器之间传送数据,载入指令用于将存储器中的数据传送到寄存器,存储指令则完毕相反的操作.经常使用的载入存储指令例如以下: -  LDR     字数据载入 ...