Uniform Generator

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

Total Submission(s): 26820 Accepted Submission(s): 10629

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

这题代码不难,关键是理解题目:seed(x+1) = [seed(x) + STEP] % MOD 这个公式是非常重要的,首先定义seed(0)等于零,然后使用公式递推,如何判断是Bad Choice和Good Choice在于0到mod-1每个数都存在与之相等的种子,写入代码就是循环的次数是否与mod相等,还有要注意输出格式,10个间距,字母前有4个空格

AC代码:

#include <stdio.h>
int seed[1000005]={0};
int main (){
long long i,step,mod;
while (scanf("%I64d%I64d",&step,&mod)!=EOF) {
i=0;
do{ seed[i+1]=(seed[i]+step)%mod;
i++;
}while(seed[i]);
if(i==mod)
printf("%10I64d%10I64d Good Choice\n\n",step,mod);
else
printf("%10I64d%10I64d Bad Choice\n\n",step,mod);
}
return 0;
}

HDU 1014 G题的更多相关文章

  1. 2017Summmer_上海金马五校 F题,G题,I题,K题,J题

    以下题目均自己搜 F题  A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...

  2. HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Subm ...

  3. Asia Yokohama Regional Contest 2018 G题 What Goes Up Must Come Down

    链接 G题 https://codeforces.com/gym/102082 使其成为单峰序列需要交换多少次相邻的数. 树状数组维护逆序对. 对于每个序列中的数,要么在单峰的左侧,要么在单峰的右侧, ...

  4. hdu - 6282,2018CCPC湖南全国邀请赛G题,字符串,规律

    HDU – 6282 http://acm.hdu.edu.cn/showproblem.php?pid=6282 by Hzu_Tested 题意:给出两个字符串S和T,只由a,b,c三种字符组成( ...

  5. G题 hdu 1466 计算直线的交点数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1466 计算直线的交点数 Time Limit: 2000/1000 MS (Java/Others)  ...

  6. HDU 6270 Marriage (2017 CCPC 杭州赛区 G题,生成函数 + 容斥 + 分治NTT)

    题目链接  2017 CCPC Hangzhou Problem G 题意描述很清晰. 考虑每个家庭有且仅有$k$对近亲的方案数: $C(a, k) * C(b, k) * k!$ 那么如果在第$1$ ...

  7. HDU 6249 Alice’s Stamps(2017 CCPC-Final G题,DP)

    题目链接 HDU 6249 题意 给定$m$个区间,在这些区间中选出不超过$k$个,求被覆盖的点的数量的最大值. 设$f[i][j]$表示选到第$i$个点并选了$j$个区间的时候能得到的最大答案. 处 ...

  8. HDU 5863 cjj's string game ( 16年多校10 G 题、矩阵快速幂优化线性递推DP )

    题目链接 题意 : 有种不同的字符,每种字符有无限个,要求用这k种字符构造两个长度为n的字符串a和b,使得a串和b串的最长公共部分长度恰为m,问方案数 分析 : 直觉是DP 不过当时看到 n 很大.但 ...

  9. Infinite Fraction Path HDU 6223 2017沈阳区域赛G题题解

    题意:给你一个字符串s,找到满足条件(s[i]的下一个字符是s[(i*i+1)%n])的最大字典序的长度为n的串. 思路:类似后缀数组,每次倍增来对以i开头的字符串排序,复杂度O(nlogn).代码很 ...

随机推荐

  1. python ctrl+c

    #!/usr/bin/env pythonimport signalimport sysimport osdef signal_handler(signal, frame): print('You p ...

  2. UVA 11464 - Even Parity 状态压缩,分析 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. Linux系统默默改变了人类世界的生活方式

    你知道操作系统都有些什么吗?Windows啊.这是我在上大学之前的问答,我当时认为只一种叫做Windows的操作系统,可是我错了,当我上大学以后,作为计算机专业的一名学生的时候我第一次接触到了除Win ...

  4. HTML(二)选择器

    1.id选择器 一对一关系 <div id="only">123</div> #only{ background-color:black; } 2.clas ...

  5. MySQL字符集与校对

    一.什么是字符集与校对 1.字符集与校对 字符集是指一种从二进制编码到某种字符符号的映射. 校队是指一组用于某个字符集的配许规则. 2.utf8与utf8mb4 标准的UTF-8字符集编码是可以使用1 ...

  6. Struts2的基础知识

    Struts2属于MVC框架 Struts2的优点: 1.侵入性低 2.提供了拦截器,可以利用拦截器进行AOP编程 3.提供了类型转换器 4.支持多种表示层技术:jsp,freeMarker,Vele ...

  7. 图的关键路径,AOE,完整实现,C++描述

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  8. Linux文件系统中的inode节点详细介绍

    这篇文章主要介绍了Linux文件系统中的inode节点,详细讲解了inode是什么.inode包含的信息.inode号码的相关资料等,需要的朋友可以参考下 一.inode是什么? 理解inode,要从 ...

  9. Linux 目录配置标准:FHS

    目录 应放置内容 /bin 和/user/目录下的/bin/都是用来保存的系统命令 /sbin 和/user/目录下的/sbin是用来保存root的系统命令 /boot 这个目录主要放置开机所用的文件 ...

  10. php安装及配置笔记

    windows下启动php-cgi方式为:php-cgi.exe -b 127.0.0.1:9000 -c php.ini(也可以是绝对路径). 安装XDebug支持,最基本的配置参数为: [xdeb ...