题目:
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
**理解:**就是给定两个数step, mod然后利用给定的公式求随机数,保证从0到mod减1范围内都均匀出现。
两种方法1, 求最大公约数,不是1 就good,2. 直接计算出所有的seed 然后排序,看是否和0-mod-1相等。
1.

//
//  main.cpp
//  hud1014
//
//  Created by zhan_even on 2018/10/20.
//  Copyright © 2018年 zhan_even. All rights reserved.
//#include <iostream>
using namespace std;int gcd(int step, int mod){int z,i,gcdnum;gcdnum = 0;if(step<mod)z = step;else z = mod;for(i=z; i>0 ;i--){if(step%i==0 && mod%i==0){gcdnum = i;break;}}return gcdnum;
}
int main(int argc, const char * argv[]) {int step, mod;while (cin>>step>>mod) {printf("%10d%10d", step,mod);if (gcd(step, mod)==1)cout<<"    Good Choice"<<endl<<endl;elsecout<<"    Bad Choice"<<endl<<endl;}return 0;
}

`
2.

//
//  main.cpp
//  hdu1013
//
//  Created by zhan_even on 2018/10/19.
//  Copyright © 2018年 zhan_even. All rights reserved.
//#include <iostream>
#include <algorithm>
using namespace std;int main(int argc, const char * argv[]) {int step, mod, i;int s[100001];while (cin>>step>>mod) {s[0] = 0;for (i = 1; i<mod; i++)s[i] = (s[i-1] + step)%mod;sort(s, s+mod);for(i=0;i<mod;i++)if(s[i]!=i)break;printf("%10d%10d",step,mod);if(i==mod)cout<<"    Good Choice"<<endl<<endl;elsecout<<"    Bad Choice"<<endl<<endl;}return 0;
}

`
hdu 1019

//
//  main.cpp
//  hdu1019
//
//  Created by zhan_even on 2018/10/20.
//  Copyright © 2018年 zhan_even. All rights reserved.
//#include <iostream>
using namespace std;long long gcd(long long a, long long b){long long z,i,gcdnum;gcdnum = 0;if(a<b)z = a;else z = b;for(i=z; i>0 ;i--){if(a%i==0 && b%i==0){gcdnum = i;break;}}return gcdnum;
}int main(int argc, const char * argv[]) {int pronum;cin >> pronum;while (pronum--) {int numnum;cin >> numnum;long long num[10000];int i;for(i = 0;  i<numnum; i++){if (i == 0) {cin >> num[i];}else{cin >> num[i];num[i]=num[i-1]*num[i]/gcd(num[i-1],num[i]);}}cout << num[numnum-1] <<endl;}return 0;
}

最大公约数:
根据欧几里得算法可以知道:a,b的最大公约数同时也是a mod b 的最大公约数
所以如果a 和 b的全为0,那么他们的最大公约数不存在,如果其中一个为0则最大公约数为不是0的那个数字,如果都不为0,则让新的a = b, 新b = b%a 然后重复该过程。

hdu 1014 +hdu 1019 (求最小公倍数或者排序)相关推荐

  1. (hdu step 2.1.1)最小公倍数(使用最大公约数来辅助求最小公倍数)

    题目: 最小公倍数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  2. 刷题日记【第四篇】-笔试必刷题【Fibonacci数列+合法括号序列判断+两种排序方法+求最小公倍数】

    目录 选择题模块 1. 以下对继承的描述错误的是(A) 2. 在Java中,一个类(B) 3. 以下不是Object 类的方法的是(D) 4. Test.main() 函数执行后的输出是(D) 编程题 ...

  3. HDU 1853 HDU 3488【有向环最小权值覆盖问题 】带权二分图匹配 KM算法

    HDU 1853 & HDU 3488[有向环最小权值覆盖问题 ]最小费用最大流 In the kingdom of Henryy, there are N (2 <= N <= ...

  4. HDU 1853 HDU 3488【有向环最小权值覆盖问题 】最小费用最大流

    HDU 1853 & HDU 3488[有向环最小权值覆盖问题 ]带权二分图匹配 KM算法 In the kingdom of Henryy, there are N (2 <= N & ...

  5. light_oj 1236 求最小公倍数( lcm(a,b) )等于n的数对 素因数分解

    light_oj 1236 求最小公倍数( lcm(a,b) )等于n的数对  素因数分解 H - Pairs Forming LCM Time Limit:2000MS     Memory Lim ...

  6. HDU 3518 HDU 4416【后缀自动机len的使用】

    max:即代码中 len 变量,它表示该状态能够接受的最长的字符串长度. min:表示该状态能够接受的最短的字符串长度.实际上等于该状态的 fail 指针指向的结点的 len + 1. max-min ...

  7. C语言实现辗转相除法和更相减损法求两数最大公约数,及求最小公倍数的方法

    在学习从C语言过程中,我们会遇到一个题目,求两个整数的最大公约数,那么接下来分别介绍两种方法求最大公约数 1,辗转相除法 辗转相除法, 又名欧几里德算法(Euclidean Algorithm),是求 ...

  8. 母函数+例题(hdu 2079+hdu 2082)

    母函数+例题(hdu 2079+hdu 2082) 虽然ACM的确有点力不从心,但是还是贵在坚持,继续啃啃算法..... 昨天一个下午学了学母函数,离散数学+幂级数,只能说nb- 看了半天的原理,结果 ...

  9. 常见算法:C语言求最小公倍数和最大公约数三种算法

    最小公倍数:数论中的一种概念,两个整数公有的倍数成为他们的公倍数,当中一个最小的公倍数是他们的最小公倍数,相同地,若干个整数公有的倍数中最小的正整数称为它们的最小公倍数,维基百科:定义点击打开链接 求 ...

最新文章

  1. python wxpy_wxpy
  2. 谁说LINQ复杂查询不支持返回实名类型~复杂结果集中再使用复杂结果集
  3. C语言连接MYSQL存取数据的一个例子
  4. navicat导出数据到oracle,使用Navicat premium导出oracle数据库中数据到SQL server2008数据库中...
  5. 使用ueditor实现多图片上传案例——DaoImpl层(ShoppingDaoImpl)
  6. 剑指 Offer 51. 数组中的逆序对(归并排序做法)
  7. pythonlist循环添加元素_list.append()在for循环中每次添加的都是最后的一个元素汗血宝马...
  8. 达观杯文本智能处理(1)
  9. c语言二级题库中会有错题吗,二级C语言题库-改错题
  10. 三电平igbt死区时间计算_三电平IGBT功率模块
  11. 黑苹果驱动 hackintosh
  12. 关于linux系统安装zabbix报错的解决方案
  13. nvm 安装node版本报错clang: error: no such file or directory: ‘CXX=c++‘
  14. 如何衡量一个量化策略的好坏
  15. vue提示Named Route ‘News‘ has a default child route. When navigating to this named route...问题
  16. 埃拉托色尼筛选法巧解质数问题(埃氏筛法求解素数问题)
  17. Centos7最小化安装升级至图形化
  18. 女神联盟2服务器停止注册,女神联盟2新区,平台几天开一次新区
  19. BAPI_GOODSMVT_CREATE(调拨 收货 发货 入库 退货)BAPI
  20. 典型的多层神经网络模型,多层变量神经网络分析

热门文章

  1. 张学友:男人四十正当年
  2. C++笔记 指针函数与函数指针详解
  3. 搜搜产品日记——IM聊天助手优化
  4. MySQL最常用数据引擎(InnoDB、MylSAM、MEMORY)详解及如何选择合适的存储引擎
  5. 学习总结4.1 Linux文件权限修改
  6. 小程序中rpx转换成px
  7. 【限时优惠】第五届云计算大会社区门票抢购
  8. 燃尽图,甘特图,鱼骨图
  9. mybatis分页插件的使用
  10. Git - 拉取远程分支并创建本地分支