HDU-1852-Beijing 2008-一个神奇的公式求逆元
Posted ofshk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU-1852-Beijing 2008-一个神奇的公式求逆元相关的知识,希望对你有一定的参考价值。
As we all know, the next Olympic Games will be held in Beijing in 2008. So the year 2008 seems a little special somehow. You are looking forward to it, too, aren‘t you? Unfortunately there still are months to go. Take it easy. Luckily you meet me. I have a problem for you to solve. Enjoy your time.
Now given a positive integer N, get the sum S of all positive integer divisors of 2008 N. Oh no, the result may be much larger than you can think. But it is OK to determine the rest of the division of S by K. The result is kept as M.
Pay attention! M is not the answer we want. If you can get 2008 M, that will be wonderful. If it is larger than K, leave it modulo K to the output. See the example for N = 1,K = 10000: The positive integer divisors of 20081 are 1、2、4、8、251、502、1004、2008,S = 3780, M = 3780, 2008 M % K = 5776.
Now given a positive integer N, get the sum S of all positive integer divisors of 2008 N. Oh no, the result may be much larger than you can think. But it is OK to determine the rest of the division of S by K. The result is kept as M.
Pay attention! M is not the answer we want. If you can get 2008 M, that will be wonderful. If it is larger than K, leave it modulo K to the output. See the example for N = 1,K = 10000: The positive integer divisors of 20081 are 1、2、4、8、251、502、1004、2008,S = 3780, M = 3780, 2008 M % K = 5776.
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-一个神奇的公式求逆元的主要内容,如果未能解决你的问题,请参考以下文章
[Windows Server 2008] MySQL单数据库迁移方法
[Windows Server 2008] 阿里云.云主机忘记密码解决方法