SOJ1022 Uniform Generator
Computer simulations often require random numbers. One way to generate pseudo-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 and MOD-1. One problem with functions of this form is that they will always generate the same pattern over and over. In order to minimize this effect, selecting the STEP and MODvalues carefully can result in a uniform distribution of all values between (and including) 0 and MOD-1.
For example, if STEP = 3 and MOD = 5, the function will generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a repeating cycle. In this example, all of the numbers between and including 0 and MOD-1 will be generated every MOD iterations of the function. Note that by the nature of 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 and MOD-1, it will generate pseudo-random numbers uniformly with every MODiterations.
If STEP = 15 and MOD = 20, the function generates the series 0, 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 seed will generate all of the numbers from 0 and MOD-1.
Your program will determine if choices of STEP and MOD will generate a uniform distribution of pseudo-random numbers.
Input
Each line of input will contain a pair of integers for STEP and 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 in columns 11 through 20 and either ``Good Choice" or ``Bad Choice" left-justified starting in column 25. The ``Good Choice" message should be printed when the selection of STEP and MOD will generate all the numbers between and including 0 and MOD-1 when MOD numbers are generated. 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
思路:
若两者互质即为Good Choice,否则为bad,具体可见:https://blog.csdn.net/synapse7/article/details/12210369
但需要注意的是中间的空格是4个,有空行,需要两个回车
AC代码:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <math.h>
using namespace std;
typedef long long ll;
const int maxn = + ;
const int mods = 1e9 + ; int gcd(int a,int b){
if(b==)return a;
else return gcd(b,a%b);
} int main(){
int s,m;
while(scanf("%d%d",&s,&m)==){
printf("%10d%10d ",s,m);
if(gcd(s,m)==){
printf("Good Choice\n\n");
}else {
printf("Bad Choice\n\n");
}
}
return ;
}
SOJ1022 Uniform Generator的更多相关文章
- HDU 1014:Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Uniform Generator 分类: HDU 2015-06-19 23:26 11人阅读 评论(0) 收藏
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- uva 408 Uniform Generator
Uniform Generator Computer simulations often require random numbers. One way to generate pseudo-ran ...
- HDU 1014 Uniform Generator【GCD,水】
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1014 Uniform Generator(题解)
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1014 Uniform Generator(模拟和公式)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java ...
- (杭电 1014)Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDOJ 1014 Uniform Generator(公约数问题)
Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...
- 1014 Uniform Generator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
随机推荐
- Java基础教程(14)--嵌套类
Java允许在一个类中定义另外一个类,这样的类被称为嵌套类,就像下面这样: class OuterClass { ... class NestedClass { ... } } 嵌套类分为两种 ...
- 《码出高效 Java开发手册》第六章 数据结构与集合
码云: https://gitee.com/forxiaoming/JavaBaseCode/blob/master/EasyCoding/src/collection/index.md 6.1 数据 ...
- js判断用户是否离开当前页面
简介 VisibilityChange 事件:用于判断用户是否离开当前页面 Code // 页面的 visibility 属性可能返回三种状态 // prerender,visible 和 hidde ...
- 浅谈FIle协议与Http协议及区别
背景 先看三段代码: index.html: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- JavaWeb学习总结(七):通过Servlet生成验证码及其应用 (BufferedImage类)
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- 关于CSS的知识
这两天在学习关于HTML的知识,今天学习到CSS的知识,将自己所收获的知识点归纳一下: 首先, CSS声明学习: 1.在head标签中使用style标签声明: ...
- 转:JS判断值是否是数字(两种方法)
JS判断值是否是数字 1.使用isNaN()函数 isNaN()的缺点就在于 null.空格以及空串会被按照0来处理 NaN: Not a Number /***判断是否是数字***/ 1 2 3 ...
- Android实战——GreenDao3.2的使用,爱不释手
1前言 GreenDao是一款操作数据库的神器,经过了2.0版本的升级后,已经被广泛的开发者使用.确实是很好用,入门简单,可以剩去了数据库的建表操作和数据库SQL的编写,博主用了一次之后爱不释手,和以 ...
- this and super
this 和 super 的区别:this, 先从本类找属性和方法,本类找不到再从父类找.super, 从父类找. this 和 super 都可以调用构造方法,所以this() 和 super() ...
- 如何在微软Windows平台上打造出你的Linux开发环境(转载)
如何在微软Windows平台上打造出你的Linux开发环境 投递人 itwriter 发布于 2013-12-10 11:18 评论(1) 有348人阅读 原文链接 [收藏] « » 英文原文: ...