$数论$

$这个题已经忘了怎么做了,也不想知道了,只记得看了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 ;
}

最新文章

  1. UP board 漫谈(1)——从Atom到UP Board
  2. angular使用post、get向后台传参的问题
  3. python字符串格式化方法 format函数的使用
  4. ajax 轮循
  5. Java实体书写规范
  6. Storm安装与实验
  7. java工具类–自动将数据库表生成javabean
  8. Ant 简易教程
  9. MVC MVC+EF快速搭建
  10. sehll 小脚本的应用
  11. webpack代码分离 ensure 看了还不懂,你打我(转)
  12. 【h5+c3】web前端实战项目、快装webapp手机案例源码
  13. June.19 2018, Week 25th Tuesday
  14. MySQL:System.Data.Entity ,MySqlCommand, MySqlParameter and &quot;LIKE&quot; %
  15. C++:vector的用法详解
  16. node-rsa 非对称加密和解密
  17. k8s 的使用
  18. mysql主从复制搭建中几种log和pos详解
  19. storm从入门到放弃(三),放弃使用 StreamId 特性
  20. 关于thinkpad安装win10操作系统

热门文章

  1. HDU 5667 :Sequence
  2. PHP中使用Redis
  3. Canvas学习笔记——缓动
  4. 宜信开源|分布式任务调度平台SIA-TASK的架构设计与运行流程
  5. ORACLE时间函数(SYSDATE)简析
  6. STL algorihtm算法iter_swap(29)
  7. 【BZOJ3218】a + b Problem 可持久化线段树优化建图
  8. 九度OJ 1120:全排列 (DFS)
  9. 基于Netty自研网关中间件
  10. 不懂不能装懂--邮箱后缀“inc”的含义