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的时候应该怎么办,这样就 ...
随机推荐
- 笔记-python-tutorial-4.controlflow( and function)
笔记-python-tutorial-4.controlflow( and function) 1. 函数 1.1. 定义函数 def name(x): “””函数的第一行语句可以是可 ...
- Spring核心技术(十四)——ApplicationContext的额外功能
在前文的介绍中我们知道,org.springframework.beans.factory包提供了一些基本的功能来管理和控制Bean,甚至通过编程的方式来实现.org.springframework. ...
- Java并发——synchronized和ReentrantLock的联系与区别
0 前言 本文通过使用synchronized以及Lock分别完成"生产消费场景",再引出两种锁机制的关系和区别,以及一些关于锁的知识点. 本文原创,转载请注明出处:http:// ...
- nable to execute dex: Multiple dex files define Lcom/chinaCEB/cebActivity/R
用proguaid 只混淆Android项目的src下的包的话,如果出现了上面的问题: nable to execute dex: Multiple dex files define Lcom/chi ...
- 面试常问 Java基础 冒泡排序
冒泡排序就是对一个数组进行排序. 用双层for循环就可以解决. 第一层,决定排序的次数. n个数,进行n-1次排序就行了. 第二层,把相邻的两个数比较,谁小,放到后面和下一个数字比较,谁小谁放到后面, ...
- spring整合mybatis详解
在上篇螃蟹已经说明spring注解的最经典配置,接下来开始整合mybatis,这样整个项目就相对完整了. 有关本实例的源码可以到 <spring MVC注解实例及说明文档> 下载. 如需转 ...
- hnust 搬书
问题 G: 搬书 时间限制: 1 Sec 内存限制: 128 MB提交: 576 解决: 49[提交][状态][讨论版] 题目描述 XCQ队长要退役啦,由于队长常年刷题,机位上摆着各类算法书,一个 ...
- python的重重之器(生成器、迭代器、装饰器)
一.装饰器 1.定义:本质是函数,装饰其他函数就是为其他函数添加附件功能. 2.原则: a.不能修改被装饰的函数的源代码: b.不能修改被装饰的函数的调用方式: 实例: #!/usr/bin/env ...
- Python面向对象之类的继承(2)
1.除了封装,Python面向对象还有继承这一功能,如下代码,这是简单的继承功能. class Animal: def chi(self): print(self.name+' 吃') def he( ...
- oracle 修改数据 保险方法
oracle 中修改比较安全的方法:(pl/sql) 第一种方法: select * from temp where id=9 for update; 第二种方法: select t.*,rowid ...