标签:com ble clu comm long time 题意 mpi amp
InputThe input consists of several test cases. Each test case contains a line with two integers N and K (1 ≤ N ≤ 10000000, 500 ≤ K ≤ 10000). N = K = 0 ends the input file and should not be processed.
Output
For each test case, in a separate line, please output the result.
Sample Input
1 10000 0 0
Sample Output
5776
题意:
好好理解看清楚:
S=2008^x,所有因子和 get the sum S of all positive integer divisors of 2008 N.
M=S%k(已知k) the rest of the division of S by K. The result is kept as M
求2008^M%k
1 #include<stdio.h> 2 typedef long long ll; 3 4 ll ksm(ll x,ll n,ll mod) 5 { 6 ll res=1; 7 while(n>0) 8 { 9 if(n&1) 10 res=res*x%mod; 11 x=x*x%mod; 12 n>>=1; 13 } 14 return res%mod; 15 } 16 17 18 //S=2008^x,所有因子和 get the sum S of all positive integer divisors of 2008 N. 19 //M=S%k(已知k) the rest of the division of S by K. The result is kept as M 20 //求2008^M%k 21 22 int main() 23 { 24 ll n,k; 25 while(~scanf("%lld %lld",&n,&k)) 26 { 27 if(n==0&&k==0) 28 break; 29 ll k2=ksm(2,3*n+1,k*250); 30 if(k2-1<0) 31 k2=k2-1+k; 32 else 33 k2--; 34 35 ll k251=ksm(251,n+1,250*k); 36 if(k251-1<0) 37 k251=k251-1+k; 38 else 39 k251--; 40 41 ll M=k2*(k251)%(250*k)/250; 42 // ll M=k2*(k251/k)%(250*k); 43 // ll M=k2*(k251/250)%(250*k); WA,注意一下 44 ll ans=ksm(2008,M,k); 45 printf("%lld\n",ans); 46 } 47 return 0; 48 }
HDU-1852-Beijing 2008-一个神奇的公式求逆元
标签:com ble clu comm long time 题意 mpi amp
原文地址:https://www.cnblogs.com/OFSHK/p/11386302.html