# BZOJ4833: [Lydsy1704月赛]最小公倍佩尔数（min-max容斥）

${f}_{n}=2{f}_{n-1}+{f}_{n-2}$$f_n = 2f_{n-1}+f_{n-2}$

$\text{lcm}{f}_{T}=\prod _{S\in T}{f}_{gcd\left\{S\right\}}^{\left(-1{\right)}^{|S|+1}}$

$\prod _{d|n}{g}_{d}={f}_{n}$

$\begin{array}{ccc}\text{lcm}{f}_{\left\{T\right\}}& =& \prod _{S\in T}{f}_{gcd\left\{S\right\}}^{\left(-1{\right)}^{|S|+1}}\\ & =& \prod _{S\in T}\left(\prod _{d|gcd\left\{S\right\}}{g}_{d}{\right)}^{\left(-1{\right)}^{|S|+1}}\\ & =& \prod _{d}{g}_{d}^{\sum _{S\in T,d|gcd\left\{S\right\}}\left(-1{\right)}^{|S|+1}}\end{array}$

#include <bits/stdc++.h>
using namespace std;

const int RLEN=1<<18|1;
inline char nc() {
static char ibuf[RLEN],*ib,*ob;
return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
char ch=nc(); int i=0,f=1;
while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc(); }
return i*f;
}
inline void W(int x) {
static int buf[50];
if(!x) {putchar('0'); return;}
if(x<0) {putchar('-'); x=-x;}
while(x) {buf[++buf[0]]=x%10; x/=10;}
while(buf[0]) {putchar(buf[buf[0]--]+'0');}
}

const int N=1e6+50; int mod;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}
inline int mul(int x,int y) {return (long long)x*y%mod;}
inline int power(int a,int b,int rs=1) {for(;b;b>>=1,a=mul(a,a)) if(b&1) rs=mul(rs,a); return rs;}

int n,f[N],g[N];
inline void solve() {
n=rd(), mod=rd();
f[1]=1; f[2]=2;
for(int i=1;i<=n;i++) g[i]=1;
for(int i=1;i<=n;i++) {
g[i]=mul(f[i],power(g[i],mod-2));
for(int j=i+i;j<=n;j+=i) g[j]=mul(g[j],g[i]);
}
int ans=0;
for(int i=1;i<=n;i++) {
}