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. ASCII编码、Unicode编码、UTF-8

    一.区别 ASCII.Unicode 是“字符集” UTF-8 .UTF-16.UTF-32  是“编码规则” 其中: 字符集:为每一个「字符」分配一个唯一的 ID(学名为码位 / 码点 / Code ...

  2. R语言常用操作

    1 取整运算 在编程实现的时候有时会碰到对数值取整的需求,而取整的方式却多种多样,依赖于具体问题,不过在R中已经配备了种类齐全的相关函数,主要包括以下五种: floor():向下取整: ceiling ...

  3. HTML5 ④

    块元素和行元素: 1.行元素:在一行内显示,不会自动换行的标签.不能设置宽高. 块元素:自动换行的标签,能设置宽高.*利于我们页面布局   比如:段落标签,标题标签都是块元素 2.两者可以互相转换,通 ...

  4. 【转】Java迭代:Iterator和Iterable接口

    Java迭代 : Iterator和Iterable接口 从英文意思去理解 Iterable :故名思议,实现了这个接口的集合对象支持迭代,是可迭代的.able结尾的表示 能...样,可以做.... ...

  5. vue-router-6-命名视图

    //展示多个视图<router-view class="view one"></router-view> <router-view class=&qu ...

  6. urllib 获取页面或发送信息

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- #urllib提供了一系列用于操作URL的功能. #urllib的request模块可以非常方便地抓取UR ...

  7. PSP0级记录2

                              上课         编写程序               课外资料               日总计     3.13 周一           ...

  8. Android : 移植curl-7.61.1 及 openssl-1.1.0i

    一.curl-7.61.1 Android平台移植: libcurl是一个免费且易于使用的客户端URL传输库,支持DICT.FILE.FTP.FTPS.Gopher.HTTP.HTTPS.IMAP.I ...

  9. 1.4socket服务器打印信息的四种不同方式()

    方式一 socker 服务器 # -*- coding: utf-8 -*- import sys,os,multiprocessing from socket import * serverHost ...

  10. CentOS7安装Nginx及配置

    Nginx是一款轻量级的网页服务器.反向代理服务器.相较于Apache.lighttpd具有占有内存少,稳定性高等优势.**它最常的用途是提供反向代理服务.** 安装   在Centos下,yum源不 ...