Beijing 2008

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)
Total Submission(s): 741    Accepted Submission(s): 291

Problem Description
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 2008N.
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 2008M,
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, 2008M % K = 5776.

 
Input
The
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
 
收获挺大的!。以前对于除法模运算只知道用逆元可以算,,但是当两个数不互素的时候就不知道怎么弄了。今天得到了两个公式。。第一个公式自己做的时候想到了可能可以,然后真的AC了,然后去验证发现真的有:
1.(a/b)%mod=a%(b*mod)/b%mod;(get这个公式好激动)

2.(a/b)%mod=a*b^(mod-2)%mod,mod为素数(可以通过逆元证明)(这个公式的话感觉如果mod为素数的话,直接用逆元也一样的,,可以参考我博客hdu1452)

然后这个题并不难,把2008分解成 251*2^3 然后求因子和用第一个公式去掉分母250,然后可以得到M,在用快速幂计算就好了。

#include <stdio.h>
#include <iostream>
using namespace std;
typedef long long LL; LL pow_mod(LL a,LL n,LL mod){
LL ans = ;
while(n){
if(n&) ans = a*ans%mod;
a=a*a%mod;
n=n>>;
}
return ans;
} int main()
{
LL N,K;
while(scanf("%lld%lld",&N,&K)!=EOF,N&&K)
{
K = *K;
LL M = ((pow_mod(,N+,K)-)*(pow_mod(,*N+,K)-))%K;
M = M/;
K/=;
LL ans =pow_mod(,M,K);
printf("%lld\n",ans);
}
return ;
}

最新文章

  1. CWMP开源代码研究4——认证流程
  2. Linux json解析jq
  3. 真机调试时遇到“Could not launch *** process launch failed: Security”的解决办法
  4. 关于已配置log4j,运行tomcat时显示警告的分析
  5. ios中常见数据存储方式以及SQLite常用的语句
  6. brew安装
  7. ThreadLocal的设计与使用(原理篇)
  8. ajax的同步和异步问题 (转)
  9. 设置searchBar上右边取消按钮的颜色
  10. ASP.NET的学习之asp.net整体运行机制
  11. 解决VS2013/VS2010简体中文版无法使用ReSharper快捷键的问题
  12. vs2010 mvc3创建的razor引擎模板页,子页面引用后出现当前上下文中不存在名称“ViewBag”
  13. 实例:ABAP Tree Control 使用与ALV Grid对象关联
  14. html的target用法
  15. 用HTML和javascript(JS)计算触屏手机手指滑动方向的演示
  16. 《深入浅出设计模式》读书笔记 C#版(第一章)
  17. ACM个人零散知识点整理
  18. 【JSOI2008】最大数
  19. 使用everything把一个文件夹里(包含子目录)的所有图片拷贝到另一个文件夹
  20. 详解散列hashCode在HashMap中的使用原理

热门文章

  1. FZU 2082 过路费(树链剖分)
  2. 图论:HDU2544-最短路(最全、最经典的最短路入门及小结)
  3. Detecting iOS
  4. CQRS之旅——旅程3(订单和注册限界上下文)
  5. 虚拟架构就绪 | 谈谈Windows Server 2012 R2迁移这件小事
  6. jmeter连接数据库之增删改查
  7. tinyipa make
  8. [译]为什么pandas有些命令用括号结尾,有些则没有?
  9. Map的常用方法keySet()、entrySet()
  10. linux下编译libmysqlclient, 安装mysql-server mysql-client