HDU 6363
题意略。
思路:
这里有两个结论需要注意:
1.gcd(a ^ x - 1,a ^ y - 1) = a ^ gcd(x,y) - 1
2.gcd(fib[x],fib[y]) = fib[gcd(x,y)]
详见代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6 + ;
const LL mod = 1e9 + ;
const LL mm = 1e9 + ; LL inv[maxn * + ],fac[maxn * + ];
bool check[maxn];
LL prime[maxn],mu[maxn],f[maxn],n,k; LL exgcd(LL a,LL b,LL& x,LL& y){
if(a == && b == ) return -;
if(b == ){
x = ,y = ;
return a;
}
LL d = exgcd(b,a % b,y,x);
y -= a / b * x;
return d;
}
LL rev(LL a,LL n){
LL x,y;
LL d = exgcd(a,n,x,y);
return (x % n + n) % n;
}
void init_inv(){
fac[] = ;
for(LL i = ;i < * maxn;++i) fac[i] = fac[i - ] * i % mod;
inv[ * maxn - ] = rev(fac[ * maxn - ],mod);
for(LL i = * maxn - ;i >= ;--i){
inv[i] = (i + ) * inv[i + ] % mod;
}
}
LL C(LL a,LL b){
LL m = a,n = b;
return ((fac[n] * inv[m]) % mod * inv[n - m]) % mod;
}
void init(){
f[] = ,f[] = ;
for(int i = ;i < maxn;++i){
f[i] = (f[i - ] + f[i - ]) % mm;
}
}
void mobius(){
memset(check,false,sizeof(check));
mu[] = ;
int tot = ;
for(LL i = ;i < maxn;++i){
if(!check[i]){
prime[tot++] = i;
mu[i] = -;
}
for(int j = ;j < tot;++j){
if(i * prime[j] > maxn) break;
check[i * prime[j]] = true;
if(i % prime[j] == ){
mu[i * prime[j]] = ;
break;
}
else mu[i * prime[j]] = -mu[i];
}
}
}
LL qmod(LL a,LL n){
LL ret = ;
while(n){
if(n & ) ret = ret * a % mod;
a = a * a % mod;
n = n>>;
}
return ret;
} int main(){
init_inv();
mobius();
init();
int T;
scanf("%d",&T);
while(T--){
scanf("%lld%lld",&n,&k);
LL denominator = C(n,n + k - );
denominator = rev(denominator,mod);
LL ans = ;
for(int i = ;i <= n;++i){
if(n % i) continue;
LL div = i;
LL contri = (qmod(,f[div]) - + mod) % mod;
LL cnt = ;
for(LL j = div;j <= n;j += div){
if(n % j) continue;
LL d = j;
cnt += mu[d / i] * C(n / d,n / d + k - ) % mod;
cnt = (cnt % mod + mod) % mod;
}
ans += contri * cnt % mod;
ans %= mod;
}
ans = ans * denominator % mod;
printf("%lld\n",ans);
}
return ;
}
HDU 6363的更多相关文章
- hdu 6363 bookshelf
题解讲的很清楚了,直接看代码就懂了 题解:http://bestcoder.hdu.edu.cn/blog/2018-multi-university-training-contest-6-solut ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- JAVA-Spring框架之IOC(DI)(1)
spring框架概述 spring是一个service层的框架,可以整合许多其 他框架,进行工作 spring的主要技术是IOC(DI)和AOP IOC(DI)-控制反转(依赖注入)AOP - 面向切 ...
- go 学习笔记之工作空间
搭建好 Go 的基本环境后,现在可以正式开始 Go 语言的学习之旅,初学时建议在默认的 GOPATH 工作空间规范编写代码,基本目录结构大概是这个样子. . |-- bin | `-- hello.e ...
- spring注解不支持静态变量注入
spring注解不支持静态变量注入:今天敲代码 自动配置 配置: Animal.java package study01_autoconfig.beanConfig; import org.spri ...
- mac下安装mongodb数据库教程
前言 由于最近在学习node+express,学习到持久化存储章节需要连接mongodb数据库,然后之前也有试过安装mongodb但是失败了,这次就找了很多资料,终于安装完成了,故此记录下来安装步骤, ...
- 90后iOS开发者的出路,如何规划30岁前的自己(程序员必修课)
前言: 最近发生了一些和我们没有直接关系但是有间接关系的事情.比如华为“清洗”高龄基层员工,比如游戏公司2号员工拿不到股份而离职.先不说事实到底如何,起码很多码农是心有戚戚焉. 最近一年多也发生了一些 ...
- python使用pip安装第三方库以及镜像使用豆瓣源安装第三方库
2018/8/7 在使用pip安装pynum第三方库时的随笔 所有的前提都是你成功安装了pip 首先第一步 打开命令提示符 输入pip show pip 查看当前pip版本 然后可以上官网搜索一下 ...
- 本地NTP服务器与客户端配置
1. NTP 简介 NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 在集群中,为了保证各节点之间的时间一致,我们通常需要配置本地的 NT ...
- TI MSP430工程配置及2019年电赛A题编程示例(使用430 F5529)
配置 第一步:右击工程,选择Options 第二步:在General Options的Target选项卡里选择对应的器件Device,这里是MSP430G2231 第三步:在Debugger里选择FE ...
- sublime text 3 15个常用插件介绍
1.ColorPicker 功能:调色板(需要输入颜色时,可直接选取颜色) 使用:快捷键Windows: ctrl+shift+c 2.Emmet 功能:编码快捷键,前端必备 使用:在输入代码段后,按 ...
- 02、安装Linux系统
1.我们打开VM软件,然后点击“创建新的虚拟机”,选择“经典”选项 2.选中“稍后安装操作系统”单选按钮,然后单击“下一步”按钮 3.将客户机操作系统的类型选择为“Linux”,版本为"Re ...