Problem Description

Computer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form

seed(x+1) = [seed(x) + STEP] % MOD

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 MOD values 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 MOD iterations.

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 (1 <= STEP, MOD <= 100000).

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

题目这么长,其实意思就是判断输入的2个数的最大公约数是不是1.

如果是输出:Good Choice

否则输出:Bad Choice

还有注意的是:输出后面跟一个空行。其实我也不知道是输出之间还是输出之后(英语水平有限)。我是输出之后跟一个空行,AC了。

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int a = sc.nextInt();
int b = sc.nextInt();
if(gcd(a,b)==1){
System.out.printf("%10d%10d",a,b);
System.out.println(" Good Choice");
}else{
System.out.printf("%10d%10d",a,b);
System.out.println(" Bad Choice");
}
System.out.println();
}
} //递归求最大公约数
private static int gcd(int a, int b) {
return b==0?a:gcd(b,a%b);
} }

HDOJ 1014 Uniform Generator(公约数问题)的更多相关文章

  1. HDU 1014 Uniform Generator(模拟和公式)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java ...

  2. HDU 1014 Uniform Generator【GCD,水】

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. HDU 1014:Uniform Generator

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. HDU 1014 Uniform Generator(题解)

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. HDU 1014 Uniform Generator(最大公约数,周期循环)

    #include<iostream> #include <cstdio> #include <cstring> using namespace std; int m ...

  6. HDU 1014 Uniform Generator 欧几里得

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 解题思路: 1. 把题目意思读懂后,明白会输入两个数,然后根据题中的公式产生一系列伪随机数,看这 ...

  7. hdu 1014.Uniform Generator 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目意思:给出 STEP 和 MOD,然后根据这个公式:seed(x+1) = [seed(x) ...

  8. 1014 Uniform Generator

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  9. 1014 Uniform Generator ACM

    http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目的英文实在是太多了 ,搞不懂. 最后才知道是用公式seed(x+1) = [seed(x) + STE ...

随机推荐

  1. Flash上传组件之SWFUpload文件上传

    一.什么是SWFUpload? SWFUpload是一个客户端文件上传工具,最初由Vinterwebb.se开发,它通过整合Flash与JavaScript技术为WEB开发者提供了一个具有丰富功能继而 ...

  2. 第二篇:Power BI数据可视化之基于Web数据的报表制作(经典级示例)

    前言 报表制作流程的第一步显然是从各个数据源导入数据,Power BI能从很多种数据源导入数据:如Excel,CSV,XML,以及各类数据库(SQL Server,Oracle,My SQL等),两大 ...

  3. Codeforces 526D - Om Nom and Necklace 【KMP】

    ZeptoLab Code Rush 2015 D. Om Nom and Necklace [题意] 给出一个字符串s,判断其各个前缀是否是 ABABA…ABA的形式(A和B都可以为空,且A有Q+1 ...

  4. asp.net,mvc4,mysql数据库,Ef遇到问题集合

    asp.net  mvc  mysql数据库,在我一个新手自学MVC4时遇到如下的问题,一一解决掉的方法记录如下方便自己日后查看,也为了方便一些像我一样的新手遇到如下问题时,提供参考 问题一: 解决办 ...

  5. The requested URL ***** was not found on this serve

    Wamp的Alias具体是干什么用的,后面要研究一下!!!! 我是之前创建了一个站点用Alias,后来把站点文件移到了www下后,除了首页都访问不了了.显示“The requested URL *** ...

  6. 网站项目:让一般处理文件.ashx的代码有折叠功能(#region)

    注意:该方法用于网站项目.但对于其他类型的项目有一定的参考作用. 1.首先在你想被别人访问的位置新建一个ashx文件,如/System/xxx.ashx. 新建xxx.ashx的代码如下: [csha ...

  7. 加入强调语气,使用<strong>和<em>标签

    有了段落又有了标题,现在如果想在一段话中特别强调某几个文字,这时候就可以用到<em>或<strong>标签. 但两者在强调的语气上有区别:<em> 表示强调,< ...

  8. Solution(项目部署):The server does not support version 3.0 of the J2EE Web module specification

    1.错误: 在eclipse中使用run->run on server的时候,选择tomcat6会报错误:The server does not support version 3.0 of t ...

  9. memset 初始化数组

    memset是初始化一段内存区域的函数,其头文件是<string.h>,以前经常使用出现错误,整理一下. C++ Reference对于memset的定义为: void * memset ...

  10. 【USACO 1.4.3】等差数列

    [题目描述] 一个等差数列是一个能表示成a, a+b, a+2b,..., a+nb (n=0,1,2,3,...)的数列. 在这个问题中a是一个非负的整数,b是正整数.写一个程序来找出在双平方数集合 ...