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 ...
随机推荐
- 移植X264成功
http://blog.csdn.net/mashang123456789/article/details/8673426 http://blog.csdn.net/b5w2p0/article/de ...
- crawler_基础之_httpclient 访问网络资源
先粘贴一个 简单版的,后期再修改 pom文件 <dependency> <groupId>org.apache.httpcomponents</groupId> & ...
- ocp11g培训内部教材_052课堂笔记(042)_体系架构
OCP 052 课堂笔记 目录 第一部分: Oracle体系架构... 4 第一章:实例与数据库... 4 1.Oracle 网络架构及应用环境... 4 2.Oracle 体系结构... 4 3. ...
- JavaEE Tutorials (1) - 概述
1.1 Java EE 7平台新增特性3 1.2 Java EE应用模型3 1.3 分布式多层应用4 1.3.1 安全4 1.3.2 Java EE组件5 1.3.3 Java EE客户端6 1.3. ...
- linux_常用命令_(ls, lsof,nslookup)_查看文件按照时间排序
平时收集些用到的命令 方便使用 1: ls -lrt 按时间排序 展示 2:nslookup 查看dns解析 3:lsof -p 进程号 lsof `which httpd` //那个进程在使用 ...
- Eclipse 引导阮卓项目 No projects are found to import解
我们指示import当项目.由于一些git项目不.project和.classpath档.因此,直接import当然不是现有项目. 下面是解决方式: 1. new Android Project里面换 ...
- Topcoder SRM 628 DIV 2
被自己蠢哭了.... 250-point problem 国际象棋棋盘上给出两个坐标,问象从一个走到还有一个最少要几步. 黑格象仅仅能走黑格,白格象仅仅能走白格,仅仅要推断两个坐标的颜色是否同样就能推 ...
- Duanxx的STM32学习:NVIC操作
版权声明:本文博客原创文章,博客,未经同意,不得转载.
- C#中ISpostback
响应客户端控件时ispostback为true 代码: using System; using System.Collections.Generic; using System.Linq; using ...
- java传值和通过引用传递
第一次使用int实验: public class TTEST { private static List<UserEntity> mList = new LinkedList<Use ...