#include<iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void)
{
int s,m,i;
/*int seed=0;
int a[10005]={0};
//memset(a,0,sizeof(a));*/
while(scanf("%d%d",&s,&m)!=EOF);
{
int seed=0;
int a[10005]={0};
while(!a[seed])//
{
a[seed]=1;//若本位0,变换标志位为1,直到出现循环到头,标志过了的就跳出
seed=(seed+s)%m;//seed根据随机数公式变化
}
for(i=0;i<m;i++)//范围0-m
{
if(a[i]==0)//只要有没出现在0~m-1的数就不好
{
printf("%10d%10d Bad Choice\n\n",s,m);
break;
}
}
if(i==m){ //跳出循环后,刚好以m为周期
printf("%10d%10d Good Choice\n\n",s,m);
}
}
}

  

#include<iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int gcd(int a,int b)
{
if(a<b)
swap(a,b);
return b?gcd(b,a%b):a;
}
int main()
{
int i,j,s,m;
while(~scanf("%d%d",&s,&m))
{
if(gcd(s,m)==1)
{
printf("%10d%10d Good Choice\n\n",s,m);
}
else
{
printf("%10d%10d Bad Choice\n\n",s,m);
}
}
return 0;
}

  

#include <stdio.h>
#include <stdlib.h> int main()
{
int step,mod,seed,count;
while(scanf("%d%d",&step,&mod)!=EOF)
{
seed=0,count=1;
do
{
seed=(seed+step)%mod;
count++;
}while(seed!=0);
count--;
printf("%10d%10d ",step,mod);
if(count==mod)
printf("%s\n","Good Choice");
else
printf("%s\n","Bad Choice");
printf("\n");
}
system("pause");
return 0;
}

  

#include<iostream>
using namespace std; int main()
{
int s,m,x,c;
while(scanf("%d%d",&s,&m)!=EOF)
{
x=c=0;
do
{
x=(x+s)%m;
++c;
} while(x!=0); if(c==m)
printf("%10d%10d Good Choice\n\n",s,m);
else
printf("%10d%10d Bad Choice\n\n",s,m);
}
return 0;
}

  

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. Metrics+ElasticSearch+grafana

    Metrics+ElasticSearch+grafana--性能监控解决方案 https://blog.csdn.net/Shiyaru1314/article/details/76906461 利 ...

  2. 关于<meta http-equiv="Content-Type" content="text/html:charset=UTF-8">

    meta是html的元标签,其中包含了对应html的相关信息,客户端浏览器或服务端程序都会根据这些信息进行处理.我们以<meta http-equiv="Content-Type&qu ...

  3. [Leetcode] rotate image 旋转图片

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  4. 【NOIP模拟赛】书 数学+期望概率

    biubiu~~~ 对于这道傻题.........我考场上退了一个多小时才推出来这个东西是排列...........然后我打的dfs效率n!logInf正好n=9是最后一个能过的数结果前三个点的n全是 ...

  5. [COGS 2089.] 平凡的测试数据 带权并查集

    差点就撸上LCT了....... 带权并查集就是在并查集的基础上稍作修改,我的用穿址实现的有人用记录原父亲来实现. #include<cstdio> #define N 300010 us ...

  6. bzoj 1124 [POI2008]枪战Maf 贪心

    [POI2008]枪战Maf Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 741  Solved: 295[Submit][Status][Disc ...

  7. kubernetes 参考资料

    kubernetes 参考资料 非常建议先花20分钟,完成这个官方的交互式指南:https://kubernetes.io/docs/tutorials/kubernetes-basics/ 这个教程 ...

  8. Idea 部署非Maven项目

    参考:http://m.blog.csdn.net/z69183787/article/details/78030857 以前一直很好奇,在idea中运行tomcat,把项目部署到其中,运行起来,然后 ...

  9. [POJ2068]Nim解题报告

    Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones ...

  10. bzoj 1150 贪心

    首先选取的线段一定是相邻两个端点线段,那么我们贪心的考虑这个问题,我们先在这n-1条线段中选出最短的一条,然后将这条线段的值改为左面的线段的值+右面的线段的值-自己的值,用这条线段取代原来这三条线段, ...