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. 2机器学习实践笔记(k-最近邻)

    1:算法是简单的叙述说明 由于训练数据样本和标签,为测试数据的示例,从最近的距离k训练样本,此k练样本中所属类别最多的类即为该測试样本的预測标签. 简称kNN.通常k是不大于20的整数,这里的距离通常 ...

  2. java_OutOfMorryError 内存溢出(replaceAll)

    最近在使用string类中的replaceAll函数时碰到这个错误,由于string长度比较长,文本文档9M多,可以增加jvm的内存大小解决. 下面是一篇对OutOfMorryError错误的一些处理 ...

  3. 百度地图API 添加自定义标注 多点标注

    原文:百度地图API 添加自定义标注 多点标注 分四个文件 location.php map.css 图片 数据库 数据库配置自己改下 -------------------------------- ...

  4. MVC 发布到 windows2003遇到 'System.Web.WebPages.Razor 错误提示

    摘自: http://blog.csdn.net/lanqiao825/article/details/7840606 http://bbs.maticsoft.com/forum.php?mod=v ...

  5. .Net2.0 --Winform结合WebBrowser控件和Socket老技术来实现另类Push~

    原文:.Net2.0 --Winform结合WebBrowser控件和Socket老技术来实现另类Push~ 目前的企业级开发比较流行的是Web2.0技术,但是由于Web技术基于请求--响应的交互模式 ...

  6. MySql绿色版配置及使用详解

    原文:MySql绿色版配置及使用详解 最近在做项目开发时用到了MySql数据库,在看了一些有关MySql的文章后,很快就上手使用了.在使用的过程中还是出现了一些问题,因为使用的是绿色免安装版的MySq ...

  7. Entity Framework查询原理

    Entity Framework查询原理 前言 Entity Framework的全称是ADO.NET Entity Framework,是微软开发的基于ADO.NET的ORM(Object/Rela ...

  8. ASP.NET MVC中对Model进行分步验证的解决方法

    原文:ASP.NET MVC中对Model进行分步验证的解决方法 在我之前的文章:ASP.NET MVC2.0结合WF4.0实现用户多步注册流程中将一个用户的注册分成了四步,而这四个步骤都是在完善一个 ...

  9. 学习Easyui

    学习Easyui 社区easyui 论坛:http://bbs.jeasyuicn.com API地址:http://www.jeasyuicn.com/api 简单桌面版:http://app.bt ...

  10. shell 批量压缩指定文件夹及子文件夹内图片

    shell 批量压缩指定文件夹及子文件夹内图片 用户上传的图片,一般都没有经过压缩,造成空间浪费.因此须要编写一个程序,查找文件夹及子文件夹的图片文件(jpg,gif,png),将大于某值的图片进行压 ...