HDU 5832 A water problem

    xiaoxiao2021-03-26  33

    HDU 5832 A water problem

    编程能力题,大数

    想当初打网预时这题。。写了半天JAVA,都是MLE。。C++大数的板子也各种挂。。最后队友过的这题。。赛后也没去看。。现在回忆一下,补个题解,长个见识。

    传送门:HDU


    题意

    给你一个很大的数,数字位数有10000000个。问你它是不是73和137的倍数。


    思路

    同时是73和137的倍数,这数必定是10001(137*73)的倍数。 一个数字一个数字的处理,再利用取模的性质,可以得到 res=(res*10+a)%mod 想不明白的话想想一个数字一个数字读入,怎么转化成一个数?就是读一个数字,把原来结果*10加上它。


    代码

    #include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #include<string> #include<cstring> #include<vector> #include<cmath> #include<queue> #define _ ios_base::sync_with_stdio(0);cin.tie(0); using namespace std; const int MAXN=5005; const int oo=0x3f3f3f3f; typedef long long LL; const LL loo=4223372036854775807ll; const int MOD=73*137; char a[10000007]; int main() {_ int res=0; int count=0; while(scanf("%s",a)==1) { for(int i=0;i<strlen(a);i++) { res=(res*10+(a[i]-'0'))%MOD; } cout<<"Case #"<<++count<<": "; cout<<(res==0 ? "YES" : "NO")<<endl; res=0; } //system("pause"); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-663079.html

    最新回复(0)