大数取模-HDU 5832-A water problem

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SZU_Crayon/article/details/82083490
  • 大数取模-HDU 5832-A water problem


  • 题目链接:

A water problem

  • 思路:

题目大意:

第一颗星球周期为73,第二颗星球周期为137,问N是否为两颗星期的共同周期第一天

题目思路:

把两个周期的最小公倍数求出,是10001,只要那个数能被10001整除就YES

看看N的取值: the length of N is up to 10000000.明显大数问题

大数的取模,从高位到低位逐位取模,Res=( 10*Res+( N[i] - ‘0’  )%10001 ) 

  • 代码:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAX_Length 10001000
char N[MAX_Length];
int main()
{
    int t=0;
    while(scanf("%s",N)!=EOF)
    {
        int n=0;
        int Len=strlen(N);
        for(int i=0;i<Len;i++)
            n=(10*n+(N[i]-'0'))%10001;
        if(n==0)
            cout<<"Case #"<<++t<<": YES"<<endl;
        else
            cout<<"Case #"<<++t<<": NO"<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/SZU_Crayon/article/details/82083490
今日推荐