HDU-1852-Beijing 2008-一个神奇的公式求逆元
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
#include<stdio.h>
typedef long long ll; ll ksm(ll x,ll n,ll mod)
{
ll res=;
while(n>)
{
if(n&)
res=res*x%mod;
x=x*x%mod;
n>>=;
}
return res%mod;
} //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 int main()
{
ll n,k;
while(~scanf("%lld %lld",&n,&k))
{
if(n==&&k==)
break;
ll k2=ksm(,*n+,k*);
if(k2-<)
k2=k2-+k;
else
k2--; ll k251=ksm(,n+,*k);
if(k251-<)
k251=k251-+k;
else
k251--; ll M=k2*(k251)%(*k)/;
// ll M=k2*(k251/k)%(250*k);
// ll M=k2*(k251/250)%(250*k); WA,注意一下
ll ans=ksm(,M,k);
printf("%lld\n",ans);
}
return ;
}
HDU-1852-Beijing 2008-一个神奇的公式求逆元的更多相关文章
- HDU 1852 Beijing 2008 数论
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1852 这道题和HDU1452类似. 题意:给你一个n.k,让你求2008^n所有因子的和(包括1和本 ...
- HDU 5407 CRB and Candies(LCM +最大素因子求逆元)
[题目链接]pid=5407">click here~~ [题目大意]求LCM(Cn0,Cn1,Cn2....Cnn)%MOD 的值 [思路]来图更直观: 这个究竟是怎样推出的.说实话 ...
- 一个简单的公式——求小于N且与N互质的数的和
首先看一个简单的东西. 若$gcd(i,n)=1$,则有$gcd(n-i,n)=1$ 于是在小于$n$且与$n$互质的数中,$i$与$n-i$总是成对存在,且相加等于$n$. 考虑$i=n-i$的特殊 ...
- HDU1852 Beijing 2008(快速幂+特殊公式)
As we all know, the next Olympic Games will be held in Beijing in 2008. So the year 2008 seems a lit ...
- hdu 1852(快速幂模+有除法的时候取模的公式)
Beijing 2008 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others)Tota ...
- HDU 1014 Uniform Generator(模拟和公式)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java ...
- 【Luogu】P3327约数个数和(莫比乌斯反演+神奇数论公式)
题目链接 真TM是神奇数论公式. 注明:如无特殊说明我们的除法都是整数除法,向下取整的那种. 首先有个定理叫$d(ij)=\sum\limits_{i|n}{}\sum\limits_{j|m}{}( ...
- hdu 3117 Fibonacci Numbers 矩阵快速幂+公式
斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...
- modifytime是一个神奇的column name----这边文章是错的totally,因为我的实验不彻底。timestamp属性很神奇,头一个timestamp,会自动的成DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
在mysql里边modifytime是一个神奇的column name,试一下. 请执行sql语句 CREATE TABLE `test_time` ( `modifytime` timestamp ...
随机推荐
- element-UI 点击一行,背景色变化
代码: @row-click="rowClick" 当某一行被点击时会触发该事件 :row-class-name="tableRowClassName" 可以 ...
- visual studio snippet备忘
一.C++ classheadercpp.snippet <?xml version="1.0" encoding="utf-8"?> <Co ...
- 【luoguP3701】「伪模板」主席树
description byx和诗乃酱都非常都非常喜欢种树.有一天,他们得到了两颗奇怪的树种,于是各自取了一颗回家种树,并约定几年后比一比谁种出来的树更加牛x. 很快,这棵树就开花结果了.byx和诗乃 ...
- params拦截器
1. params拦截器首先给action中的相关参数赋值,如id 2. prepare拦截器执行prepare方法,prepare方法中会根据参数,如id,去调用业务逻辑,设置model对象 ...
- P1802 5倍经验日
P1802 5倍经验日 题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却无奈的看着那一些比他等级高的好友,想着能否把他们干掉.干掉能拿不少经验的. 题目描述 现在absi20 ...
- c++ 11新特性学习1
static_assert 静态断言,特点是编译期的断言检查 assert 运行时期的断言检查 二者参数用法相同
- (转)Python学习笔记(1)__name__变量
Python使用缩进对齐组织代码的执行,所有没有缩进的代码,都会在载入时自动执行.每个文件(模块)都可以任意写一些没有缩进的代码,并在载入时自动执行.为了区分 主执行代码和被调用文件,Python引入 ...
- XStream入门应用程序
在进入XStream库的细节之前,让我们来看看应用程序操作.在这个例子中,我们创建Student和Address类.还将创建一个Student对象,然后将其序列化到一个XML字符串.然后反序列化的同一 ...
- 利用DOM节点找对象和直接在标签属性中调函数传值this的书写区别
同样的功能,不同的书写格式. 1.个人觉得比较繁琐的写法,但是比较常见,特别是在大项目的时候常用的就是这种方法: <div id="mouse" onmouseover=&q ...
- 内置Jetty配置JSP支持过程中的常见报错
目录 1. 常见报错及解决 1.1 JSP support not configured 1.2 JSTL标签解析 1.3 JSP编译 1.4 JSP实现依赖 1.5 EL表达式支持 2. 小结 1. ...