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( ...
随机推荐
- Python中类的属性的访问控制
因为自己是做.NET的,之前有学习过Python,喜欢这门语言的很多特性,最近又不时看了一会儿,将自己的感受分享给大家,其中也难免会用C#的角度看Python的语法,主要还是讲下Python中类中对属 ...
- Ubuntu16.04 LTS上安装Go1.10
原因 Ubuntu资源库上默认使用的是Go1.6.2版本,给最新版本代码编译带来了不少问题.本文就记录下在Ubuntu下直接安装Go最新版1.10的步骤. 准备工作 1.卸载已有版本 # 卸载已经安装 ...
- 一:Web
一:Web介绍 1.Web:网页,网络 2.Web应用:运行在网络上的应用程序 3.网络应用程序分类:C/S B/S C/S 客服端(client)/服务器(server) 典型应用:QQ,YY B/ ...
- 师范大学 e: skyscrapers
#include<iostream> #include<stdio.h> #include<cstring> #include<cstdlib> usi ...
- idea创建maven的web工程
然后一路点next 接下去添加tomcat 成功 控制台出现乱码的话 输入:-Dfile.encoding=UTF-8 控制台乱码解决
- 【学习笔记】--- 老男孩学Python,day8 知识点补充 join,列表不能循环删除,深浅copy
1. 补充基础数据类型的相关知识点 1. str. join() 把列表变成字符串 2. 列表不能再循环的时候删除. 因为索引会跟着改变 3. 字典也不能直接循环删除. 把要删除的内容记录在列表中. ...
- js中var、let、const区别
javascript中有三种声明变量的方式:var.let.const 1.var 作用域:全局或局部 var的作用域可以是全局或是局部,以下分四种情况说明: (1).当var关键字声明于函数内时是局 ...
- 【PyQt5 学习记录】005:QMainWindow 及状态栏、菜单栏和工具栏
#!/usr/bin/env python import sys from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QA ...
- APP之红点提醒三个阶段
下面这个页面就是我们进入APP后的主界面.客户选项的红点上数字就是显示我们没有查看的客户总数量. 当我们切换到客户这个fragment时,会显示贷款客户数量与保险客户数量. 当我们随便点击入一 ...
- lsnrctl 与 tnsnames.ora 的联系
平台:Windoxs XP+Oracle 11G 当使用oralce的 Net Manager创建了一个名为“L3”的Listener后,要想使用lsnrctl启动和关闭 L3 还必须在tnsname ...