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 ...
随机推荐
- 阿里云HBase推出全新X-Pack服务 定义HBase云服务新标准
2018年12月13日,第八届中国云计算标准和应用大会在京召开,会上阿里云HBase宣布推出全新X-Pack服务,支持SQL.时序.时空.图.全文检索能力.复杂分析,从处理到分析全栈式数据库,客户开箱 ...
- C#利用栈实现字符串运算解析
附上参考文章链接:https://blog.csdn.net/qq_34831781/article/details/80104219 本人整合修复一些bug后的代码 using System; us ...
- 2019/11/12 CSP模拟赛&&考前小总结
写在前面的总结 离联赛只有几天了,也马上就要回归文化课了. 有点舍不得,感觉自己的水平刚刚有点起色,却又要被抓回文化课教室了,真想在机房再赖几天啊. 像19/11/11那场的简单题,自己还是能敲出一些 ...
- Python sorted list的实现
Python sorted list的实现 具体思路是用二分保list有序+插入 class SortedList(list): K = -1 def __init__(self, K=-1): li ...
- 在Word中如何自动生成参考文献引用
来自:在Word中如何自动生成参考文献引用 在写毕业论文时,参考文献动辄就有四五十篇,在文中对照参考文献逐一引用是一件十分痛苦的事情,而且一旦参考文献的顺序发生变化,文中的引用也要逐个修改,那么,我们 ...
- hash值的计算与转换 分类: ACM TYPE 2015-05-07 17:49 36人阅读 评论(0) 收藏
#include <bits/stdc++.h> using namespace std; const int MAXN = 100; const int X = 3; long long ...
- [00]APUE:GCC / GDB / Makefile
http://blog.csdn.net/haoel/article/category/9197 http://blog.csdn.net/haoel/article/details/2886 生成 ...
- 神经网络中使用Batch Normalization 解决梯度问题
BN本质上解决的是反向传播过程中的梯度问题. 详细点说,反向传播时经过该层的梯度是要乘以该层的参数的,即前向有: 那么反向传播时便有: 那么考虑从l层传到k层的情况,有: 上面这个 便是问题所在.因为 ...
- 引入css文件时,css link和@import区别
这里link与@import介绍的是html引入css的语法单词.两者均是引入css到html的单词. 一.了解基本 1.link语法结构 <link href="CSSurl路径&q ...
- 7-MySQL高级-主从-1
1. 主从同步的定义 主从同步使得数据可以从一个数据库服务器复制到其他服务器上,在复制数据时,一个服务器充当主服务器(master),其余的服务器充当从服务器(slave). 因为复制是异步进行的,所 ...