bzoj4833
$数论$
$这个题已经忘了怎么做了,也不想知道了,只记得看了3个小时$
$对于有gcd(f_i, f_j) = f_{gcd(i, j)}性质的数列,以下结论适用$
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + ;
int n;
ll ans = , P;
ll f[N], g[N];
int m[N];
int rd()
{
int x = , f = ;
char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = x * + c - ''; c = getchar(); }
return x * f;
}
ll power(ll x, ll t)
{
ll ret = ;
for(; t; t >>= , x = x * x % P) if(t & ) ret = ret * x % P;
return ret;
}
ll inv(ll x)
{
return power(x, P - );
}
int main()
{
int T = rd();
while(T--)
{
n = rd();
P = rd();
f[] = ;
f[] = ;
for(int i = ; i <= n; ++i) f[i] = (f[i - ] * + f[i - ]) % P;
for(int i = ; i <= n; ++i) g[i] = f[i];
for(int i = ; i <= n; ++i)
{
ll t = inv(g[i]);
for(int j = i + i; j <= n ; j += i)
g[j] = g[j] * t % P;
}
ll lcm = ;
ans = ;
for(int i = ; i <= n; ++i)
{
lcm = lcm * g[i] % P;
ans = (ans + 1LL * lcm * i) % P;
}
printf("%lld\n", ans);
}
return ;
}
bzoj4833的更多相关文章
- 【BZOJ4833】最小公倍佩尔数(min-max容斥)
[BZOJ4833]最小公倍佩尔数(min-max容斥) 题面 BZOJ 题解 首先考虑怎么求\(f(n)\),考虑递推这个东西 \((1+\sqrt 2)(e(n-1)+f(n-1)\sqrt 2) ...
- BZOJ4833: [Lydsy1704月赛]最小公倍佩尔数(min-max容斥&莫比乌斯反演)(线性多项式多个数求LCM)
4833: [Lydsy1704月赛]最小公倍佩尔数 Time Limit: 8 Sec Memory Limit: 128 MBSubmit: 240 Solved: 118[Submit][S ...
- BZOJ4833: [Lydsy1704月赛]最小公倍佩尔数
Problem 传送门 Sol 容易得到 \[f_n=e_{n-1}+f_{n-1},e_{n-1}=f_{n-1}+e_{n-1},f_1=e_1=1\] 那么 \[f_n=2\times \sum ...
- bzoj4886 [Lydsy2017年5月月赛]叠塔游戏
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4886 [题解] 跟bzoj4883:http://www.cnblogs.com/galax ...
随机推荐
- linux 启动ftp服务,sftp服务
启动ftp服务:yum install vsftpd 在/etc/rc.d/init.d/目录下:命令 service vsftp start启动ssh服务,sftp服务在/etc/init.d/目录 ...
- linux下apache https 虚拟主机配置
如果单纯仅仅想在数据传输时加密传输,那么ssl证书是不须要认证的,可是浏览器打开时会有警告信息.如果我们做的不是一个公众产品那么也还好啦. 例如以下是今天学习时的一个笔记,事实上我用的是真实环境. 环 ...
- java 定义一个同步map内存去重法
实例:
- 通过串口工具下发指令的Python脚本
前言 最近一段时间在测试物联网相关的App自动化,涉及通过串口工具给硬件设备下发指令. 使用的串口工具:SecureCRT 解决办法 通过引用Python的第三方库:serial,通过编写Python ...
- JNI在C和C++中的调用区别
C-style JNI looks like (*env)->SomeJNICall(env, param1 ...) C++ style JNI looks like env->Some ...
- 实现单击列表头对ListView的动态排序
排序是根据列的类型来的,就ID列来说,int类型的排序结果是3,5,17,而如果你把该列类型改为string,结果就会是17,3,5,如果你定义列的时候不加类型,默认是string,如果是自定义类型, ...
- 【BZOJ1844/2210】Pku1379 Run Away 模拟退火
[BZOJ1844/2210]Pku1379 Run Away 题意:矩形区域中有一堆点,求矩形中一个位置使得它到所有点的距离的最小值最大. 题解:模拟退火的裸题,再调调调调调参就行了~ #inclu ...
- EasyDarwin开源音频解码项目EasyAudioDecoder:EasyPlayer Android音频解码库(第二部分,封装解码器接口)
上一节我们讲了如何基于ffmpeg-Android工程编译安卓上的支持音频的ffmpeg静态库:http://blog.csdn.net/xiejiashu/article/details/52524 ...
- poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...
- define tensorflow and run it
import tensorflow as tf a, b, c, d, e = tf.constant(5, name='input_a'), tf.constant(6, name='input_b ...