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 ...
随机推荐
- background-attachment
CreateTime--2017年9月28日10:58:58 Author:Marydon background-attachment 1.定义 定义背景图片随滚动轴的移动方式(设置背景图像是否固 ...
- 10934 - Dropping water balloons(DP)
这道题的思路非常难想. 问你须要的最少实验次数,这是非常难求解的.并且我们知道的条件仅仅有三个.k.n.实验次数 . 所以我们最好还是改变思路,转而求最高所能确定的楼层数 . 那么用d[i][j]表 ...
- python(12)- 文件处理应用Ⅰ
一.读取文件,打印第三行时后面加入“徐亚平” 程序如下: count=0 with open("test",mode="r",encoding="ut ...
- caffe搭建--ubuntu标准平台的搭建
http://caffe.berkeleyvision.org/install_apt.html Ubuntu Installation General dependencies sudo apt-g ...
- eclipse如何查问题?
问题:从SVN上拉了一个项目,莫名奇妙就报错?看着就很纠结 解决之道:在Window下拉菜单show View 找到Problems 就可以查到具体的原因,我的这个是需要添加一个tomcat服务器
- 面向对象基础——String类
String类的两种实例化方法 A:直接赋值 public class StringDemo01{ public static void main(String args[]){ String na ...
- Mvc创建并注册防盗链
创建CustomHandler.JpgHandler public class JpgHandler : IHttpHandler { public void ProcessRequest(HttpC ...
- mysql中索引的使用
索引是加速查询的主要手段,特别对于涉及多个表的查询更是如此.本节中,将介绍索引的作用.特点,以及创建和删除索引的语法. 使用索引优化查询 索引是快速定位数据的技术,首先通过一个示例来了解其含义及作用. ...
- 【计蒜客2017NOIP模拟赛1】
D1T1 题面 题解:一开始以为傻题,旋转个坐标系就行了,结果光荣爆零~ 结果发现旋转坐标系后,由于多了一些虚点,锤子砸到虚点上了~gg [没有代码] D1T2 题面 题解:计算出每个边对答案的贡献即 ...
- 九度OJ 1123:采药 (01背包、DP、DFS)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2705 解决:1311 题目描述: 辰辰是个很有潜能.天资聪颖的孩子,他的梦想是称为世界上最伟大的医师. 为此,他想拜附近最有威望的医师为师 ...