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 ;
}
hdu 1852(快速幂模+有除法的时候取模的公式)的更多相关文章
- # 模乘(解决乘法取模爆long long)
模乘(解决乘法取模爆long long) 二进制思想,变乘法为多次加法,具体思想跟着代码手算一遍就理解了,挺简单的 ll qmul(ll a,ll b,ll m) { ll ans=0; while( ...
- hdu 5187 快速幂 + 快速乘 值得学习
就是以那个ai为分水岭,左边和右边都分别是单调增或单调减如图 就这四种情况,其中头两种总共就是两个序列,也就是从头到尾递增和从头到尾递减. 后两种方式就是把序列中德数分 ...
- hdu 1061 快速幂
求n^n的个位 Sample Input 2 3 4 Sample Output 7 6 直接快速幂了,注意要用long long #include<cstdio> long long q ...
- C - Rikka with Badminton --- HDU 6425 快速幂加组合数学
---恢复内容开始--- 题目链接: https://vjudge.net/problem/1812693/origin 这题的mod运算很恶心,真的... 本题有正反两个思路,一个是正面求解其不能成 ...
- 本原串(HDU 2197 快速幂)
本原串 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 4506 快速幂
小明自从告别了ACM/ICPC之后,就开始潜心研究数学问题了,一则可以为接下来的考研做准备,再者可以借此机会帮助一些同学,尤其是漂亮的师妹.这不,班里唯一的女生又拿一道数学题来请教小明,小明当然很高兴 ...
- HDU 1097 快速幂
#include<iostream> using namespace std; long long quick(long long a,long long b,int c) { ; a=a ...
- hdu 4549 M斐波那契数列(快速幂 矩阵快速幂 费马小定理)
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4549: 题目是中文的很容易理解吧.可一开始我把题目看错了,这毛病哈哈. 一开始我看错题时,就用了一个快速 ...
- 乘方快速幂 OR 乘法快速幂
关于快速幂这个算法,已经不想多说,很早也就会了这个算法,但是原来一直靠着模板云里雾里的,最近重新学习,发现忽视了一个重要的问题,就是若取模的数大于int型,即若为__int64的时候应该怎么办,这样就 ...
随机推荐
- Visual Studio的下载安装
下载地址: 下载Visual Studio Code https://code.visualstudio.com/ 安装扩展包 安装图标 View->Extensions 搜索Icon 安装Ma ...
- Python知识点进阶——细节问题
int()强制转换浮点数 在int()的强制转换浮点数时候,不管是正数还是负数,只取整数部分. 注意:这里不是向上或者向下取整,也不是四舍五入. 无限递归 递归是为了将问题简化为更小规模的同类型问题, ...
- 权限组件(12):自动发现项目中有别名的URL
自动发现项目中所有有别名的URL,效果如下: customer_list {'name': 'customer_list', 'url': '/customer/list/'} customer_ad ...
- 洛谷P1328生活大爆炸版石头剪刀布
题目链接:https://www.luogu.org/problemnew/show/P1328
- Java中Scanner中nextLine()方法和next()方法的区别
https://blog.csdn.net/hello_word2/article/details/54895106
- Dataflow编程模型和spark streaming结合
Dataflow编程模型和spark streaming结合 主要介绍一下Dataflow编程模型的基本思想,后面再简单比较一下Spark streaming的编程模型 == 是什么 == 为用户提 ...
- PostgreSQL 数组类型
PostgreSQL 支持表的字段使用定长或可变长度的一维或多维数组,数组的类型可以是任何数据库内建的类型.用户自定义的类型.枚举类型, 以及组合类型.但目前还不支持 domain 类型. 数组类型的 ...
- 菜鸟之路——机器学习之SVM分类器学习理解以及Python实现
SVM分类器里面的东西好多呀,碾压前两个.怪不得称之为深度学习出现之前表现最好的算法. 今天学到的也应该只是冰山一角,懂了SVM的一些原理.还得继续深入学习理解呢. 一些关键词: 超平面(hyper ...
- 初识面向对象-python
Python 面向对象 一.概念的区分: 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发“更快更好 ...
- Selenium - WebDriver: Page Objects
This chapter is a tutorial introduction to page objects design pattern. A page object represents an ...