The meaning of problems
Default \ (n-\ leqslant m \) .
After the reaction can be obtained a Pomona:
\ (\ SUM \ limits_. 1} = {T} ^ {n-\ n-FRAC {} {} T \ FRAC} m {T} {\ SUM \ limits_ {D | D ^ T} k \ mu (\ frac {T } {d}) \)
In front of the division can be clearly divided blocks, followed by a multiplicative function may be linear sieve.
设\(f(x)=\sum\limits_{d|x}d^k\mu(\frac{x}{d})\)
When the linear sieve \ (I \) does not contain \ (prime_j \) NATURAL say, considering \ (I \) containing \ (prime_j \) how to do.
Set \ (g (i) \) represents \ (I \) minimum quality factor (i.e. \ (prime_j \) ) of power, i.e. \ (prime_j ^ K \) .
\ (i \ not = g ( i) \) a \ (I \) of \ (prime_j \) was removed and then counted to:
\ (F (I * prime_j) = F (\ FRAC {I} {G ( I)}) * F (G (I) * prime_j) \)
\ (G = I (I) \) will appear with the above formula: \ (F (I * prime_j) = F (I * prime_j ) * f (1) \)
time considering substituting back to the original formula:
\ (F (P ^ C) = \ SUM \ limits_ {D | D ^ P ^ C} K \ MU (\ FRAC {P ^ {C} D}) \)
\ (F (P ^ {C-. 1}) = \ SUM \ limits_ {D | P ^ {C-. 1}} D ^ K \ MU (\ FRAC {P ^ {C-. 1}} {d}) \)
found \ (F (P ^ C) = F (P ^ C) * (prime_j) ^ K + (F (. 1) ^ K * \ MU (P ^ C)) \) ( \ (F (. 1) * \ MU (P ^ C) = 0 \) ).
Then the screen can be linear, attention \ (d ^ k \) is multiplicative function.
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5000010;
const ll mod=1000000007;
int T,K,n,m;
int mu[maxn],g[maxn];
ll pw[maxn],f[maxn],sum[maxn];
bool vis[maxn];
vector<int>prime;
inline ll power(ll x,ll k,ll mod)
{
ll res=1;
while(k)
{
if(k&1)res=res*x%mod;
x=x*x%mod;k>>=1;
}
return res;
}
inline void pre_work(int n)
{
vis[1]=1;f[1]=1;mu[1]=1;
for(int i=2;i<=n;i++)
{
//cerr<<i<<endl;
if(!vis[i])prime.push_back(i),pw[i]=power(i,K,mod),f[i]=(pw[i]-1)%mod,g[i]=i,mu[i]=-1;
for(unsigned int j=0;j<prime.size()&&i*prime[j]<=n;j++)
{
vis[i*prime[j]]=1;
pw[i*prime[j]]=pw[i]*pw[prime[j]]%mod;
if(i%prime[j]==0)
{
if(i==g[i])f[i*prime[j]]=f[i]*pw[prime[j]]%mod;//+(pw[1]*mu[i*prime[j]]=0);
else f[i*prime[j]]=f[i/g[i]]*f[g[i]*prime[j]]%mod;
g[i*prime[j]]=g[i]*prime[j];
break;
}
f[i*prime[j]]=f[i]*f[prime[j]]%mod;
g[i*prime[j]]=prime[j];
mu[i*prime[j]]=-mu[i];
}
}
for(int i=1;i<=n;i++)sum[i]=(sum[i-1]+f[i])%mod;
}
inline ll solve(int n,int m)
{
if(n>m)swap(n,m);
ll res=0;
for(int l=1,r;l<=n;l=r+1)
{
r=min(n/(n/l),m/(m/l));
res=(res+1ll*(n/l)*(m/l)%mod*((sum[r]-sum[l-1])%mod+mod)%mod)%mod;
}
return (res%mod+mod)%mod;
}
int main()
{
scanf("%d%d",&T,&K);
pre_work(5000000);
while(T--)
{
scanf("%d%d",&n,&m);
printf("%lld\n",solve(n,m));
}
return 0;
}