zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    java基础(7)--方法
    java基础(6)--数组和方法
    java基础(5)--流程控制结构
    java基础(4)--运算符及表达式
    java基础(2)--进制
    Java基础(1)--JDK,变量
    quartz(8)--其他
    spring AOP 概述(三) Advisor
    spring AOP 概述(二) Pointcut
    spring AOP 概述(一) Advice
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7198881.html
Copyright © 2011-2022 走看看