那么有 g(n)=∏T⊂S,gcd(T)∣nfib(n)(−1)∣T∣+1
不妨另为 gcd 倍数且在 S 的集合为 A,那么
g(n)=∏T⊂Afib(n)(−1)∣T∣+1=fib(n)(A=∅)
f(n)=g(n)∗(∏n∣d,d!=nf(d))−1
倒过来调和级数求即可
#include<bits/stdc++.h>
#define cs const
using namespace std;
cs int N = 1e6 + 5;
cs int Mod = 1e9 + 7;
int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }
int mul(int a, int b){ return 1ll * a * b % Mod; }
int ksm(int a, int b){ int ans=1; for(;b;b>>=1,a=mul(a,a)) if(b&1) ans=mul(ans,a); return ans; }
int n, a[N], g[N], f[N], mx;
int main(){
cin >> n;
for(int i = 1, x; i <= n; i++){
scanf("%d", &x); a[x] = 1;
mx = max(mx, x);
}
f[1] = 1;
for(int i = 2; i <= mx; i++) f[i] = add(f[i-1], f[i-2]);
for(int i = mx; i >= 1; i--)
for(int j = i+i; j <= mx; j += i) a[i] |= a[j];
for(int i = 1; i <= mx; i++) g[i] = f[i];
for(int i = 1; i <= mx; i++){
int iv = ksm(g[i], Mod-2);
for(int j = i+i; j <= mx; j += i) g[j] = mul(g[j], iv);
}
int ans = 1;
for(int i = 1; i <= mx; i++) if(a[i]) ans = mul(ans, g[i]);
cout << ans; return 0;
}