2018.09.11 poj1845Sumdiv(质因数分解+二分求数列和)
传送门
显然需要先求出ab" role="presentation" style="position: relative;">abab的所有质因数和它们的指数。
但求出来之后并不能直接上等比数列求和公式。
因为这道题并不能直接求逆元。
原因?
a的某个因数有可能已经大于9901了。
于是它可能是9901的倍数。
这样就gg了。
于是我们可以二分求解等比数列的和。
代码:
#include<iostream>
#include<cmath>
#define mod 9901
#define ll long long
#define xx first
#define yy second
using namespace std;
int a,b,tot=0;
ll ans=1;
inline ll ksm(ll x,ll p){
ll ret=1;
while(p){
if(p&1)ret=ret*x%mod;
x=x*x%mod,p>>=1;
}
return ret;
}
inline ll calc(ll x,ll y){
if(!y)return 1;
if(y&1)return ((1+ksm(x,y/2+1))*calc(x,y/2))%mod;
return ((1+ksm(x,y/2+1))*calc(x,y/2-1)+ksm(x,y/2))%mod;
}
int main(){
cin>>a>>b;
for(int i=2;i*i<=a;++i){
int cnt=0;
while(a%i==0)a/=i,++cnt;
(ans*=calc(i,cnt*b))%=mod;
}
if(a-1)(ans*=calc(a,b))%=mod;
cout<<ans;
return 0;
}
2018.09.11 poj1845Sumdiv(质因数分解+二分求数列和)的更多相关文章
- POJ 1845 Sumdiv#质因数分解+二分
题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...
- 2018.09.11 poj2976Dropping tests(01分数规划)
传送门 01分数规划板子题啊. 就是简单变形移项就行了. 显然 ∑i=1na[i]∑i=1nb[i]≤k" role="presentation" style=" ...
- 2018.09.11 bzoj3629: [JLOI2014]聪明的燕姿(搜索)
传送门 一道神奇的搜索. 直接枚举每个质因数的次数,然后搜索就行了. 显然质因数k次数不超过logkn" role="presentation" style=" ...
- spoj TBATTLE 质因数分解+二分
题目链接:点击传送 TBATTLE - Thor vs Frost Giants #number-theory #sliding-window-1 Thor is caught up in a fie ...
- 2018.09.15 poj1734Sightseeing trip(floyd求最小环)
跟hdu1599差不多.. 只是需要输出方案. 这个可以递归求解. 代码: #include<iostream> #include<cstdio> #include<cs ...
- 2018.09.11 loj#10216.五指山(exgcd)
传送门 就是一个exgcd的板子. 但注意算距离差的时候是在一个环上面算. 还有,答案要开long long233... 注意这两点之后就是exgcd板子了. 代码: #include<bits ...
- 2018.09.11 bzoj47214721: [Noip2016]蚯蚓(单调队列)
传送门 好题. 目测只会多带一个log2(n+m)" role="presentation" style="position: relative;"& ...
- 2018.09.11 bzoj2208: [Jsoi2010]连通数(bitset+floyd)
传送门 听说正解是缩点+dfs? 直接bitset优化floyd传递闭包就行了.(尽管时间复杂度是假的O(n3/32)" role="presentation" styl ...
- HDU3988-Harry Potter and the Hide Story(数论-质因数分解)
Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 ...
随机推荐
- leetcode367
public class Solution { public bool IsPerfectSquare(int num) { , high = num; while (low <= high) ...
- redis详解(二)-- 数据类型详解
Redis常用数据类型详解 1,Redis最为常用的数据类型主要有以下: String Hash List Set Sorted set pub/sub Transactions 在具体描述这几种数据 ...
- 浅谈Http、TCP、UDP和 IP 的的区别
应用层:Http,超文本传输协议(HyperText Transfer Protocal):利用TCP在两台电脑(通常是Web服务器和客户端)之间传输信息的协议.客户端使用Web浏览器发起HTTP请求 ...
- 迭代器iter()
from collections import Iterable print(isinstance({},iterable)) # 判断是否可迭代 from collections import It ...
- 【转】.net 实现 语音搜索(仅限WebKit内核浏览器)
<input type="text" class="text" name="value_2" id="value_2&quo ...
- 自动选择最佳特征进行分类-SVM (Halcon)
HALCON12里的example,classify_pills_auto_select_features.hdev. 执行流程: 1.选取相关特征(本例选取color和region组的所有特征)(本 ...
- linux中与Oracle有关的内核参数详解
工作当中遇到oracle运行时CPU占用率达到90%以上,调小以下参数值后恢复正常. fs.file-max = 65536 net.core.rmem_default=262144 net.core ...
- Haskell语言学习笔记(35)Contravariant
contravariant 模块 contravariant 模块需要安装 $ cabal install contravariant contravariant-1.4 Prelude> :m ...
- javaweb登录界面连接数据库
实验关键截图 数据库界面 建表 2.登录界面 登陆失败 5 注册页面 5 注册成功 数据库截图
- 36. Valid Sudoku (Array; HashTable)
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...