1. #include<iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. using namespace std;
  5. int main(void)
  6. {
  7. int s,m,i;
  8. /*int seed=0;
  9. int a[10005]={0};
  10. //memset(a,0,sizeof(a));*/
  11. while(scanf("%d%d",&s,&m)!=EOF);
  12. {
  13. int seed=0;
  14. int a[10005]={0};
  15. while(!a[seed])//
  16. {
  17. a[seed]=1;//若本位0,变换标志位为1,直到出现循环到头,标志过了的就跳出
  18. seed=(seed+s)%m;//seed根据随机数公式变化
  19. }
  20. for(i=0;i<m;i++)//范围0-m
  21. {
  22. if(a[i]==0)//只要有没出现在0~m-1的数就不好
  23. {
  24. printf("%10d%10d Bad Choice\n\n",s,m);
  25. break;
  26. }
  27. }
  28. if(i==m){ //跳出循环后,刚好以m为周期
  29. printf("%10d%10d Good Choice\n\n",s,m);
  30. }
  31. }
  32. }

  

  1. #include<iostream>
  2. #include <stdio.h>
  3. #include <cstring>
  4. using namespace std;
  5. int gcd(int a,int b)
  6. {
  7. if(a<b)
  8. swap(a,b);
  9. return b?gcd(b,a%b):a;
  10. }
  11. int main()
  12. {
  13. int i,j,s,m;
  14. while(~scanf("%d%d",&s,&m))
  15. {
  16. if(gcd(s,m)==1)
  17. {
  18. printf("%10d%10d Good Choice\n\n",s,m);
  19. }
  20. else
  21. {
  22. printf("%10d%10d Bad Choice\n\n",s,m);
  23. }
  24. }
  25. return 0;
  26. }

  

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. int step,mod,seed,count;
  7. while(scanf("%d%d",&step,&mod)!=EOF)
  8. {
  9. seed=0,count=1;
  10. do
  11. {
  12. seed=(seed+step)%mod;
  13. count++;
  14. }while(seed!=0);
  15. count--;
  16. printf("%10d%10d ",step,mod);
  17. if(count==mod)
  18. printf("%s\n","Good Choice");
  19. else
  20. printf("%s\n","Bad Choice");
  21. printf("\n");
  22. }
  23. system("pause");
  24. return 0;
  25. }

  

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int s,m,x,c;
  7. while(scanf("%d%d",&s,&m)!=EOF)
  8. {
  9. x=c=0;
  10. do
  11. {
  12. x=(x+s)%m;
  13. ++c;
  14. } while(x!=0);
  15.  
  16. if(c==m)
  17. printf("%10d%10d Good Choice\n\n",s,m);
  18. else
  19. printf("%10d%10d Bad Choice\n\n",s,m);
  20. }
  21. return 0;
  22. }

  

HDU 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 欧几里得

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

  6. hdu 1014.Uniform Generator 解题报告

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

  7. HDOJ 1014 Uniform Generator(公约数问题)

    Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...

  8. HDU 1014 Uniform Generator 题解

    找到规律之后本题就是水题了.只是找规律也不太easy的.证明这个规律成立更加不easy. 本题就是求step和mod假设GCD(最大公约数位1)那么就是Good Choice,否则为Bad Choic ...

  9. hdu 1014 Uniform Generator 数论

    摘取于http://blog.csdn.net/kenden23/article/details/37519883: 找到规律之后本题就是水题了,不过找规律也不太容易的,证明这个规律成立更加不容易. ...

随机推荐

  1. 洛谷 P2827 蚯蚓 解题报告

    P2827 蚯蚓 题目描述 本题中,我们将用符号 \(\lfloor c \rfloor\) 表示对 \(c\) 向下取整,例如:\(\lfloor 3.0 \rfloor = \lfloor 3.1 ...

  2. Ajax缓存问题怎么解决?

    项目有时要用一些Ajax的效果,因为比较简单,也就没有去用什么Ajax.net之类的东西,手写代码也就实现了.第二天,有人向我报告错误:说是只有第一次读取的值正常,后面的值都不正常:我调试了一下 ,确 ...

  3. 浅析JavaScript的垃圾回收机制

    JavaScript语言是一门优秀的脚本语言.其中包含脚本语言的灵活性外还拥有许多高级语言的特性.例如充许构建和实例化一个对象,垃圾回收机制(GC:Garbage Collecation).通常我们使 ...

  4. cookie 是存储于访问者的计算机中的变量

    今天把javascript如何用来创建及存储cookie复习了一下,其中的一点体会拿出来和大家讨论,首先看一下基础知识: 什么是cookie cookie 是存储于访问者的计算机中的变量.每当同一台计 ...

  5. Spring事务管理—aop:pointcut expression 常见切入点表达式及事务说明

    Spring事务管理—aop:pointcut expression 常见切入点表达式及事物说明 例: <aop:config>  <aop:pointcut expression= ...

  6. bzoj1914 [Usaco2010 OPen]Triangle Counting 数三角形 计算机和

    [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 526  Solved: 2 ...

  7. 移动端浏览器touch事件的研究总结

    $("body").on("touchstart", function(e) {     e.preventDefault();     startX = e. ...

  8. LOJ tangjz的背包

    题目大意 有 \(n\) 个物品, 第 \(i\) 个物品的体积为 \(i\) 令 \(f(x)\) 为 选择 \(m\) 个物品, 体积和为 \(x\) 的方案数 令 \(V = \sum_{i=1 ...

  9. 基于MapReduce的手机流量统计分析

    1,代码 package mr; import java.io.IOException; import org.apache.commons.lang.StringUtils; import org. ...

  10. html初探

    HTML HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏 ...