Absolute Math
定义c(n)=theprimenhave,c(1)=0,c(2)=1,c(4)=1,c(6)=2f(n)=∑d∣nμ(d)2=2c(n)f(ab)=f(a)×f(b)f(gcd(a,b))∑i=1mf(n)×f(i)f(gcd(n,i))f(n)∑d∣n1f(d)∑i=1mdf(id)[gcd(i,nd)=1]f(n)∑d∣n1f(d)∑k∣ndμ(k)∑i=1mkdf(ikd)T=kdf(n)∑T∣n∑i=1mTf(iT)∑d∣Tμ(Td)f(d)F(m,n)=∑i=1mf(in),g(n)=∑d∣nμ(nd)f(d)F(m,n)=f(n)∑T∣nF(mT,T)g(T)g=μ∗1f,是一个积性函数g(1)=1g(p)=μ(p)f(1)+μ(1)f(p)=−1+12=−12g(px)[x>=2]=μ(1)f(px)+μ(p)f(px−1)=12−12=0然后递归求解,卡卡常定义c(n) = the\ prime\ n\ have,c(1) = 0, c(2) = 1, c(4) = 1, c(6) = 2 \\ f(n) = \sum_{d \mid n} \mu(d) ^ 2 = 2 ^{c(n)} \\ f(ab) = \frac{f(a) \times f(b)}{f(gcd(a, b))}\\ \sum_{i = 1} ^{m} \frac{f(n) \times f(i)}{f(gcd(n, i))}\\ f(n) \sum_{d \mid n} \frac{1}{f(d)} \sum_{i = 1} ^{\frac{m}{d}} f(id)[gcd(i, \frac{n}{d}) = 1]\\ f(n) \sum_{d \mid n} \frac{1}{f(d)} \sum_{k \mid \frac{n}{d}} \mu(k) \sum_{i = 1} ^{\frac{m}{kd}} f(ikd)\\ T = kd\\ f(n) \sum_{T \mid n} \sum_{i = 1} ^{\frac{m}{T}}f(iT) \sum_{d \mid T} \frac{\mu(\frac{T}{d})}{f(d)}\\ F(m, n) = \sum_{i = 1} ^{m} f(in), g(n) = \sum_{d \mid n} \frac{\mu(\frac{n}{d})}{f(d)}\\ F(m, n) = f(n) \sum_{T \mid n} F(\frac{m}{T}, T) g(T)\\ g = \mu * \frac{1}{f},是一个积性函数\\ g(1) = 1\\ g(p) = \frac{\mu(p)}{f(1)} + \frac{\mu(1)}{f(p)} = -1 + \frac{1}{2} = -\frac{1}{2}\\ g(p ^ x)[x >= 2] = \frac{\mu(1)}{f(p ^ x)} + \frac{\mu(p)}{f(p ^{x - 1})} = \frac{1}{2} - \frac{1}{2} = 0\\ 然后递归求解,卡卡常\\ 定义c(n)=the prime n have,c(1)=0,c(2)=1,c(4)=1,c(6)=2f(n)=d∣n∑μ(d)2=2c(n)f(ab)=f(gcd(a,b))f(a)×f(b)i=1∑mf(gcd(n,i))f(n)×f(i)f(n)d∣n∑f(d)1i=1∑dmf(id)[gcd(i,dn)=1]f(n)d∣n∑f(d)1k∣dn∑μ(k)i=1∑kdmf(ikd)T=kdf(n)T∣n∑i=1∑Tmf(iT)d∣T∑f(d)μ(dT)F(m,n)=i=1∑mf(in),g(n)=d∣n∑f(d)μ(dn)F(m,n)=f(n)T∣n∑F(Tm,T)g(T)g=μ∗f1,是一个积性函数g(1)=1g(p)=f(1)μ(p)+f(p)μ(1)=−1+21=−21g(px)[x>=2]=f(px)μ(1)+f(px−1)μ(p)=21−21=0然后递归求解,卡卡常
/*Author : lifehappy
*/
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e7 + 10, mod = 1e9 + 7, inv2 = mod + 1 >> 1;int prime[N], sum[N], g[N], f[N], cnt;bool st[N];void init() {f[1] = g[1] = 1;for(int i = 2; i < N; i++) {if(!st[i]) {prime[++cnt] = i;f[i] = 2;g[i] = mod - inv2;}for(int j = 1; j <= cnt && 1ll * i * prime[j] < N; j++) {st[i * prime[j]] = 1;if(i % prime[j] == 0) {f[i * prime[j]] = f[i];break;}f[i * prime[j]] = f[i] * 2;g[i * prime[j]] = 1ll * g[i] * g[prime[j]] % mod;}}for(int i = 1; i < N; i++) {sum[i] = (f[i] + sum[i - 1]) % mod;}
}ll solve(int m, int n) {if(m == 0) return 0;if(m == 1) return f[n];if(n == 1) return sum[m];ll ans = 0;//发现m <= 20的时候是最优的……if(m <= 20 && 1ll * n * m < N) {for(int i=1;i<=m;i++)ans = (ans + f[i * n]) % mod;return ans;}for(int i = 1; 1ll * i * i <= n; i++) {if(n % i == 0){if(g[i]){ans = (ans + solve(m / i, i) * g[i] % mod) % mod;}if(i * i !=n && g[n / i]){ans = (ans + solve(m / (n / i), n / i)*g[n / i]) % mod;}}}return ans * f[n] % mod;
}int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);init();int T;scanf("%d", &T);while(T--) {int n, m;scanf("%d %d", &n, &m);printf("%lld\n", solve(m, n));}return 0;
}
/*杭电的测评机比自己的老年机跑的还慢……
*/