标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 813 Accepted Submission(s): 392
题解:本来想着逆元的,谁知道不用逆元就行,x*(10^m - 1)/9 %k;
由于10^m - 1一定可以整除9;只需要对9*k取模,再除以9;就得到了(10^m - 1)/9 %k,乘以x在%k就好了;
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef __int64 LL; template<typename T> LL quick_mul(LL a, T n, T k){ LL ans = 1; while(n){ if(n & 1) ans = ans * a % k; n >>= 1; a = a * a % k; } return ans; } int main(){ int T, kase = 0; LL x,m,k,c; scanf("%d", &T); while(T--){ scanf("%I64d%I64d%I64d%I64d", &x,&m,&k,&c); k *= 9; LL ans = ((quick_mul(10, m, k) - 1 + k)%k/9)*x%(k/9); printf("Case #%d:\n%s\n", ++kase, ans == c?"Yes":"No"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5517939.html