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( ...
随机推荐
- [转] ASP.NET MVC 模型绑定的功能和问题
摘要:本文将与你深入探究 ASP.NET MVC 模型绑定子系统的核心部分,展示模型绑定框架的每一层并提供扩展模型绑定逻辑以满足应用程序需求的各种方法. 同时,你还会看到一些经常被忽视的模型绑定技术, ...
- Java - Float与Double类型比较
https://blog.csdn.net/wcxiaoych/article/details/42806313
- java设计模式-----17、中介者模式
概念: Mediator模式也叫中介者模式,是由GoF提出的23种软件设计模式的一种.Mediator模式是行为模式之一,在Mediator模式中,类之间的交互行为被统一放在Mediator的对象中, ...
- python中函数重载和重写
python 中的重载 在python中,具有重载的思想却没有重载的概念.所以有的人说python这么语言并不支持函数重载,有的人说python具有重载功能.实际上python编程中具有重载的目的缺 ...
- 转:JS判断值是否是数字(两种方法)
JS判断值是否是数字 1.使用isNaN()函数 isNaN()的缺点就在于 null.空格以及空串会被按照0来处理 NaN: Not a Number /***判断是否是数字***/ 1 2 3 ...
- egg.js连接和使用Mongodb
一.Egg连接Mongodb方法一 Cnpm i egg-momgo-native --save Plugin.js中配置 exports.mongo = { enable: true, pack ...
- html打造动画【系列3】- 小猫笑脸动画
猫咪容器 咱们每次画一个图片,肯定先要确定一个容器,几确定一下图形的位置和大小. <div class="mao_box"> <div class="m ...
- Spring Boot—21Actuator--监控
https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/ pom.xml <dependency&g ...
- Modify Dokuwiki Email Template 修改 Dokuwiki 邮件模板
Email Notification Templates There are two places to modify 1) log in as Admin -> configuration ...
- Django 简单用户注册
项目名 macboy app名 t1 1.项目macboy urls.py from django.conf.urls import url, include urlpatterns = [ url( ...