$数论$

$这个题已经忘了怎么做了,也不想知道了,只记得看了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的更多相关文章

  1. 【BZOJ4833】最小公倍佩尔数(min-max容斥)

    [BZOJ4833]最小公倍佩尔数(min-max容斥) 题面 BZOJ 题解 首先考虑怎么求\(f(n)\),考虑递推这个东西 \((1+\sqrt 2)(e(n-1)+f(n-1)\sqrt 2) ...

  2. BZOJ4833: [Lydsy1704月赛]最小公倍佩尔数(min-max容斥&莫比乌斯反演)(线性多项式多个数求LCM)

    4833: [Lydsy1704月赛]最小公倍佩尔数 Time Limit: 8 Sec  Memory Limit: 128 MBSubmit: 240  Solved: 118[Submit][S ...

  3. 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 ...

  4. bzoj4886 [Lydsy2017年5月月赛]叠塔游戏

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4886 [题解] 跟bzoj4883:http://www.cnblogs.com/galax ...

随机推荐

  1. vue2.0 自定义 饼状图 (Echarts)组件

    1.自定义  图表  组件 Echarts.vue <!-- 自定义 echart 组件 --> <template> <div> <!-- echart表格 ...

  2. 【NoSql】Redis实践篇-简单demo实现(一)

    Redis是一个key-value存储系统. Redis的出现,非常大程度补偿了memcached这类key/value存储的不足,在部分场合能够对关系数据库起到非常好的补充作用 Redis是一个ke ...

  3. 笔记12 export to excel (NPOI)

    1:filestream 熟悉关于文件操作 ==>fs.Seek(0, SeekOrigin.Begin);//每次打开文件, ==>若果重写覆盖的话,必须先清空 fs.SetLength ...

  4. shell-判断循环

    shell条件测试 test 每个完整的合理的编程语言都具有条件判断的功能. bash可以使用test命令,[]和()操作,还有if/then结构 字符串判断 -n string 判断字符串长度非零 ...

  5. Mataplotlib绘图和可视化

    Mataplotlib是一个强大的python绘图和数据可视化工具包 安装方法:pip install matplotlib 引用方法:import matplotlib.pyplot as plt ...

  6. how to run a continuous background task on OpenShift

    https://stackoverflow.com/questions/27152438/best-way-to-run-rails-background-jobs-with-openshift ht ...

  7. iframe仿ajax图片上传

    1.前台页面: iframe_upload.html <html> <body> <form action="upload.php" id=" ...

  8. SQL 游标示例

    DECLARE @i INT ) --给初始值 CREATE TABLE #temp_test --创建临时表 ( num ) ) ) BEGIN INSERT INTO #temp_test ( n ...

  9. [Python爬虫] Selenium自己主动訪问Firefox和Chrome并实现搜索截图

    前两篇文章介绍了安装.此篇文章算是一个简单的进阶应用吧.它是在Windows下通过Selenium+Python实现自己主动訪问Firefox和Chrome并实现搜索截图的功能. [Python爬虫] ...

  10. 【BZOJ1975】[Sdoi2010]魔法猪学院 A*

    [BZOJ1975][Sdoi2010]魔法猪学院 Description iPig在假期来到了传说中的魔法猪学院,开始为期两个月的魔法猪训练.经过了一周理论知识和一周基本魔法的学习之后,iPig对猪 ...