浏览器标题切换
浏览器标题切换end

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. 

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 }
复制代码

 

posted @   抓水母的派大星  阅读(194)  评论(0编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示