hdu 1852(快速幂模+有除法的时候取模的公式)
Beijing 2008
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others)
Total Submission(s): 741 Accepted Submission(s): 291
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 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.
0 0
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 ;
}
最新文章
- CWMP开源代码研究4——认证流程
- Linux json解析jq
- 真机调试时遇到“Could not launch *** process launch failed: Security”的解决办法
- 关于已配置log4j,运行tomcat时显示警告的分析
- ios中常见数据存储方式以及SQLite常用的语句
- brew安装
- ThreadLocal的设计与使用(原理篇)
- ajax的同步和异步问题 (转)
- 设置searchBar上右边取消按钮的颜色
- ASP.NET的学习之asp.net整体运行机制
- 解决VS2013/VS2010简体中文版无法使用ReSharper快捷键的问题
- vs2010 mvc3创建的razor引擎模板页,子页面引用后出现当前上下文中不存在名称“ViewBag”
- 实例:ABAP Tree Control 使用与ALV Grid对象关联
- html的target用法
- 用HTML和javascript(JS)计算触屏手机手指滑动方向的演示
- 《深入浅出设计模式》读书笔记 C#版(第一章)
- ACM个人零散知识点整理
- 【JSOI2008】最大数
- 使用everything把一个文件夹里(包含子目录)的所有图片拷贝到另一个文件夹
- 详解散列hashCode在HashMap中的使用原理
热门文章
- FZU	2082 过路费(树链剖分)
- 图论:HDU2544-最短路(最全、最经典的最短路入门及小结)
- Detecting iOS
- CQRS之旅——旅程3(订单和注册限界上下文)
- 虚拟架构就绪 | 谈谈Windows Server 2012 R2迁移这件小事
- jmeter连接数据库之增删改查
- tinyipa make
- [译]为什么pandas有些命令用括号结尾,有些则没有?
- Map的常用方法keySet()、entrySet()
- linux下编译libmysqlclient, 安装mysql-server mysql-client