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 ...
随机推荐
- bat命令闪退问题
今天执行一个bat命令,然而会出现问题:双击执行bat命令时,命令提示符界面会闪退. 然而该bat命令在他人电脑上可正常执行,而我会遇到这种问题. 以下是我尝试的方法: 首先尝试编辑bat命令,在ba ...
- 解密Kafka吞吐量高的原因
众所周知kafka的吞吐量比一般的消息队列要高,号称the fastest,那他是如何做到的,让我们从以下几个方面分析一下原因. 生产者(写入数据) 生产者(producer)是负责向Kafka提交数 ...
- 通过VS2017发布.net core程序并使用Web 部署到远程服务器最新教程
最近一个项目中,为App开发后台接口,技术选型为最新 .net core版本,使用.net core开发web api接口过程中,为了方便app团队成员直接在线调用接口,找了公网上的一台服务器做为ap ...
- vue教程(四)--其他实用用法补充
一.vue生命周期简单介绍 var App={ template:'', data(){ }, beforeCreated:function(){ //不能操作数据,只是初始化了事件等.. }, cr ...
- Hadoop自学系列集(三) ---- Hadoop安装
这节就开始讲述Hadoop的安装吧.在这之前先配置下SSH免密码登录,为什么需要配置这个呢?大家都知道Hadoop集群中可能有几十台机器甚至是上千台机器,而每次启动Hadoop都需要输入密码才能够登录 ...
- 在eclipse中创建Web项目中没有web.xml的解决方法
右键点击项目 → “Java EE Tool” → “Generate Deployment descriptor stub” 即可生成web.xml文件
- Scrapy框架安装失败解决办法
安装报错信息 正常安装: pip3 install scrapy 出现报错信息如下: 两种解决办法 第一种方法 最根本得解决办法 需要我们安装 Microsoft Visual C++ 14.0 ...
- 【转】解决eclipse连接不到genymotion的问题
(1)很多朋友在使用genymotion开发安卓应用程序的时候,会遇见完全正确的安装但是在运行的时候仍然找不到,genymotion上的设备,在打开的devices上找不到如下图所示: (2)解决的方 ...
- A solution to the never shortened to-do list
I once told my younger sister my learning system, and the basic five doctrines of my methodology. Bu ...
- Unix-IO-同步,异步,阻塞,非阻塞-笔记篇
概念更正 https://www.zhihu.com/question/19732473 错误的四个象限分类 https://www.ibm.com/developerworks/cn/linux/l ...