#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. AJAX基本演示使用

    Servlet配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="h ...

  2. hdu 2527 Safe Or Unsafe (哈夫曼树)

    Safe Or Unsafe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. 2014end

    人.事.物. 人一年了,从十六班到十六班,从j101到j101再到A207. 她:结婚,然后走了.就是这样,干脆得我都来不及留恋.是的,再也听不到她那很温柔语气,看不到她偶尔激动时就踮起脚尖.还记得晚 ...

  4. URAL1696 Salary for Robots

    题目戳这里. 最长下降子序列单调队列求法. \(f_{i,j,k}\)表示考虑前\(i\)个数,\(g_1 = j,g_2 = k\)的方案数.转移: \[f_{i,j,k} = \sum_{p = ...

  5. bzoj4145 AMPPZ2014 The Prices 状压dp

    这个题.......很可以,很小清晰......反正正经的东西我都没想到:重点在于——————我不会处理那个多出来的路费所以当时我就骚骚的弄了一颗树包状压其实这是一个类01背包的状压在每个状态用01背 ...

  6. 使用XTU降低CPU功耗,自动执行不失效

    INTEL出品的XTU可以用来做软超频操作,给CPU/GPU加电压超频,也可以通过降低CPU/GPU电压来减少功耗. 以前用XTU设置好了之后,过一段时间就自动失效了,最近失效的频率突然很高,于是找了 ...

  7. 解决mysql的日志文件过大的问题

    https://www.2cto.com/database/201203/122984.html

  8. fuser命令找到占用资源的进程

    fuser 概述 fuser命令是用来显示所有正在使用着指定的file, file system 或者 sockets的进程信息. 例一: #fuser –m –u /mnt/usb1 /mnt/us ...

  9. (转)如何用python抓取网页并提取数据

    最近一直在学这部分,今日发现一篇好文,虽然不详细,但是轮廓是出来了: 来自crifan:http://www.crifan.com/crawl_website_html_and_extract_inf ...

  10. 【BZOJ2818】Gcd [莫比乌斯反演]

    Gcd Time Limit: 10 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 给定整数N,求1<=x,y&l ...