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 ...
随机推荐
- 查询oracle sql运行计划,一个非常重要的观点--dba_hist_sql_plan
该文章的作者给予了极大的帮助长老枯荣,为了表达我的谢意. 这适用于oracle db版本号oracle 10g或者更高的版本号. 之所以说这种看法是非常重要的,因为观点是有之一awrsqrpt报告没有 ...
- libmsgque官方主页
libmsgque 消息队列(MESSAGE QUEUE)库项目简析 注: 本文如果你已经有linux开发环境 请确保你使用本库时是tag版本号. target=libmsgque-1.0 本项目採用 ...
- C# Windows服务的创建、安装、调试
一.查看已有的Windows服务 选择菜单"开始"-〉"控制面板"-〉"管理工具"-〉"服务"来查看现有系统中的服务 二 ...
- 两种计算和输出n内5要么9除尽互惠
#include<stdio.h> int main() { int i=0,n=0; float fSum=0; scanf("%d", &n); for ( ...
- linux_ Redhat Linux配置JDK和Tomcat需要注意的地方
转:http://blog.csdn.net/hongdi/article/details/10525797 1.操作系统和安装包操作系统:Redhat Linux 6.4服务器版,桌面安装JDK:j ...
- HDU 4793 2013 Changsha Regional Collision[简单的平面几何]
圆形奖章给定半径的半径和圆形区域.另一个硬币的半径,然后在桌面上平稳.给定硬币的速(的大小和方向,vx,vy)和坐标(奖牌同心圆形区域,圆和心脏为源),Q币在一个圆形区域和多少下滑(不管是什么圆形区域 ...
- update值与原值相同时,SQL Server会真的去update还是忽略呢?
原文:update值与原值相同时,SQL Server会真的去update还是忽略呢? 考虑下面的情况: 当update值与原值相同时,SQL Server会真的去update还是忽略?例如: upd ...
- vSphere HA状况:未知配置错误解决的方法
问题:vSphere HA配置出现未知错误,导致打不开主机上的虚拟机电源,vmware client连接vcenter后,主机显示警报信息,例如以下: 解决:例如以下图,选中有问题的物理主机,然后又一 ...
- IOS中 类扩展 xib
一.类扩展(class extension,匿名分类) .格式 @interface 类名 () { // 成员变量... } // 方法声明... @end .作用 > 写在.m文件中 > ...
- 【ThinkingInC++】66、pointer Stash的使用
头文件PStash.h /** * 书本:[ThinkingInC++] * 功能:pointer Stash的头文件 * 时间:2014年10月5日14:33:15 * 作者:cutter_poin ...