• HDU 1014 Uniform Generator(最大公约数,周期循环)


    #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
    
    ",s,m);
                    break;
                }
            }
            if(i==m){ //跳出循环后,刚好以m为周期
                printf("%10d%10d    Good Choice
    
    ",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
    
    ",s,m);
            }
            else
            {
                printf("%10d%10d    Bad Choice
    
    ",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
    ","Good Choice"); 
        else
          printf("%s
    ","Bad Choice"); 
        printf("
    ");                                  
      }
      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
    
    ",s,m);
            else
                printf("%10d%10d    Bad Choice
    
    ",s,m);
        }
        return 0;
    }
    

      

  • 相关阅读:
    虚拟机linux下git clone 报SSL connect error错误
    TooManyRedirects错误
    windows2008 使用 opencv_python 出现 DLL load failed错误
    禁止别人通过开发人员工具查看网站代码
    pipreqs 执行报错问题
    Vue-router 报NavigationDuplicated的解决方案
    git 记住用户密码
    获取python所有依赖包
    修改pip的安装源
    使用pycharm发布python程序到ubuntu中运行
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7198881.html
Copyright © 2020-2023  润新知