UVA 408 (13.07.28)
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)的更多相关文章
- UVA 10392 (13.07.28)
Problem F: Factoring Large Numbers One of the central ideas behind much cryptography is that factori ...
- UVA 568 (13.07.28)
Just the Facts The expression N!, read as `` N factorial," denotes the product of the first N ...
- UVA 299 (13.07.30)
Train Swapping At an old railway station, you may still encounter one of the lastremaining ``train ...
- 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 ...
- 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 ...
- 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が ...
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- 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 ...
- UVA 253 (13.08.06)
Cube painting We have a machine for painting cubes. It is supplied withthree different colors: blu ...
随机推荐
- wsdl生成的客户端
首先, 你要先把你的WS服务启动起来,就是 比如ht tp:/ /localhost:8080/Example/services/HelloWorldService?wsdl然后在你的另一个项目中建一 ...
- Loadrunner11.00破解方法
1.下载 从http://www.jb51.net/softs/71240.html上面下载到loadrunner 11.0 2.安装loadrunner 11.0 下载之后,我是直接解压到硬盘,再安 ...
- java回顾4 Java基本数据类型
为JAVA基本数据类型.我的实在是有兴趣引用数据类型.在这里,我说的是主应用程序数据类型. 为JAVA荐两个网址: 1.http://blog.sina.com.cn/s/blog_745b874b0 ...
- ToDictionary() and ToList()
ToDictionary() and ToList() 前言: 有两个简单好用的LINQ扩展方法 ToDictionary() 和ToList(),你可能知道或不知道,但是它的的确确可以简化查询转化为 ...
- Sql数据类型转换
一.ASCII码值与字符间转换 1.ASCII()与CHAR() ASCII()返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字符串可不用''括起来,但含其 ...
- Flex 日志管理
在Flex中调试方法有两种: 一是用trace()函数,在flex builder中进行调试: 二是用logTarget类,例如以下代码: // Create a target. var logTar ...
- CSDN专家吐槽实录
今天打开CSDN发现界面上的几个图标发生了变化,一个小小的变化,却引起了诸多CSDN专家对CSDN社区未来发展的思考,我特意从群里讲对话黏贴出来,希望各位能给予积极评价和建议. 你已经是群成员了,和大 ...
- 在Cocos2d-x正在使用SQLlite数据库
SQLite,它是一个轻量级的数据库,合规ACID的关系型数据库管理系统,它的设计目标是嵌入式的,并且眼下已经在非常多嵌入式产品中使用了它,它占用资源非常的低.在嵌入式设备中,可能仅仅须要几百K的内存 ...
- 数据持久化之SP的优化—送工具类
第一点:sp存储的是键值对 getSharedPreferences 第一个參数是你保存文件的名字,第个是保存的模式一般能够默觉得0 先看普通 使用SP 存储String类型字符串吧 SharedPr ...
- C/S模式开发中如何利用WebBrowser控件制作导航窗体
原文:C/S模式开发中如何利用WebBrowser控件制作导航窗体 转自: CSDN 相信不少同学们都做过MIS系统的开发,今天这里不讨论B/S模式开发的问题.来谈谈winform开发.用过市面上常见 ...