bzoj4833
2024-09-05 09:13:10
$数论$
$这个题已经忘了怎么做了,也不想知道了,只记得看了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 ;
}
最新文章
- UP board 漫谈(1)——从Atom到UP Board
- angular使用post、get向后台传参的问题
- python字符串格式化方法 format函数的使用
- ajax 轮循
- Java实体书写规范
- Storm安装与实验
- java工具类–自动将数据库表生成javabean
- Ant 简易教程
- MVC MVC+EF快速搭建
- sehll 小脚本的应用
- webpack代码分离 ensure 看了还不懂,你打我(转)
- 【h5+c3】web前端实战项目、快装webapp手机案例源码
- June.19 2018, Week 25th Tuesday
- MySQL:System.Data.Entity ,MySqlCommand, MySqlParameter and ";LIKE"; %
- C++:vector的用法详解
- node-rsa 非对称加密和解密
- k8s 的使用
- mysql主从复制搭建中几种log和pos详解
- storm从入门到放弃(三),放弃使用 StreamId 特性
- 关于thinkpad安装win10操作系统