版本比较
我爱数论
正文
增加 702 行删除 6 行
34 行未改动35363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818222 行未改动10510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216343 行未改动20720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227363 行未改动33733833934019134134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043129 行未改动46146246346423046546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556636 行未改动6036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916 行未改动6986997007012907027032927047057067077082 行未改动71171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174219 行未改动7627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238243378258268278288292 行未改动8328338348353488368378388398409 行未改动85085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693737 行未改动97597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104121 行未改动1063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113915 行未改动34 行未改动$$
$val_1,val_2,val_3,val_4$ 都可以整除分块做,所以就做完了.
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define int long longusing namespace std;constexpr int mod = 19940417,inv6 = 3323403;int n,m;inline int sum2(const int &l,const int &r){ return (r*(r+1)%mod*(2*r+1)%mod*inv6%mod-(l-1)*l%mod*(2*l-1)%mod*inv6%mod+mod)%mod;}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin >> n >> m; if(n>m){ swap(n,m); } int val1 = 0,val2 = 0,val3 = 0,val4 = 0; for(int l = 1,r = 1;l<=n;l = r+1){ r = min(n,n/(n/l)); val1 = (val1+(r-l+1)*(l+r)/2%mod*(n/l)%mod)%mod; } for(int l = 1,r = 1;l<=m;l = r+1){ r = min(m,m/(m/l)); val2 = (val2+(r-l+1)*(l+r)/2%mod*(m/l)%mod)%mod; } for(int l = 1,r = 1;l<=n;l = r+1){ r = min(n,m/(m/l)); val3 = (val3+(r-l+1)*(l+r)/2%mod*(m/l)%mod)%mod; } for(int l = 1,r = 1;l<=n;l = r+1){ r = min({n,n/(n/l),m/(m/l)}); val4 = (val4+sum2(l,r)*(n/l)%mod*(m/l)%mod)%mod; } cout << (((((((n*n%mod*m%mod*m%mod-n*n%mod*val2%mod+mod)%mod-m*m%mod*val1%mod+mod)%mod+val1*val2%mod)%mod-n*n%mod*m%mod+mod)%mod+n*val3%mod)%mod+m*val1%mod)%mod-val4+mod)%mod; return 0;}```:::
## [[HAOI2011] Problem b](https://www.luogu.com.cn/problem/P2522)
### 题意
22 行未改动$$
整除分块即可.
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define int long longusing namespace std;constexpr int N = 5e4+1;int n,a,b,c,d,k,mu[N];int primes[N],len = 0;bitset<N>st;void init(){ mu[1] = 1; for(int i = 2;i<N;++i){ if(!st[i]){ primes[++len] = i; mu[i] = -1; } for(int j = 1;j<=len&&i*primes[j]<N;++j){ st[i*primes[j]] = true; if(i%primes[j] == 0){ mu[i*primes[j]] = 0; break; } mu[i*primes[j]] = -mu[i]; } } for(int i = 1;i<N;++i){ mu[i]+=mu[i-1]; }}int f(int a,int b){ int res = 0; for(int l = 1,r = 1;l<=min(a/k,b/k);l = r+1){ r = min({min(a/k,b/k),(a/k)/((a/k)/l),(b/k)/((b/k)/l)}); res+=((a/k)/l)*((b/k)/l)*(mu[r]-mu[l-1]); } return res;}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); init(); cin >> n; while(n--){ cin >> a >> b >> c >> d >> k; cout << f(b,d)-f(a-1,d)-f(b,c-1)+f(a-1,c-1) << '\n'; } return 0;}```:::
## [[SDOI2015] 约数个数和](https://www.luogu.com.cn/problem/P3327)
### 题意
43 行未改动$$
我们预处理 $\mu,\tau$ 的前缀和,然后直接整除分块即可。
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define int long longusing namespace std;constexpr int N = 5e4+1;int T,n,m,tau[N];int primes[N],len = 0;int mu[N];bitset<N>st;void init(){ mu[1] = tau[1] = 1; for(int i = 2;i<N;++i){ if(!st[i]){ primes[++len] = i; mu[i] = -1; tau[i] = 2; } for(int j = 1;i*primes[j]<N;++j){ st[i*primes[j]] = true; if(i%primes[j] == 0){ int t = i,cnt = 0; while(t%primes[j] == 0){ ++cnt; t/=primes[j]; } tau[i*primes[j]] = tau[t]*(cnt+2); break; } mu[i*primes[j]] = -mu[i]; tau[i*primes[j]] = tau[i]*tau[primes[j]]; } } for(int i = 1;i<N;++i){ mu[i]+=mu[i-1]; tau[i]+=tau[i-1]; }}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); init(); cin >> T; while(T--){ cin >> n >> m; if(n>m){ swap(n,m); } int res = 0; for(int l = 1,r;l<=n;l = r+1){ r = min({n,n/(n/l),m/(m/l)}); res+=(mu[r]-mu[l-1])*tau[n/l]*tau[m/l]; } cout << res << '\n'; } return 0;}```:::## [[SDOI2017] 数字表格](https://www.luogu.com.cn/problem/P3704)
### 题意
63 行未改动$$\prod_{T=1}^n F^{\lfloor \frac{n}{T} \rfloor \lfloor \frac{m}{T} \rfloor}(T)$$
我们发现 $F(T)$ 可以 $O(n \ln n)$ 预处理,所以这题直接整除分块即可.时间复杂度为 $O(n \ln n + q \sqrt n \log n)$我们发现 $F(T)$ 可以 $O(n \ln n)$ 预处理,所以这题直接整除分块即可.时间复杂度为 $O(n \ln n + q \sqrt n \log n)$。
代码中给出的实现在预处理 $F$ 时重复调用了 ``qpow``,所以代码中的实现是 $O(n \log n \log mod+q \sqrt n \log mod)$ 的,不过依然能过就是了。
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define int long longusing namespace std;constexpr int N = 1e6+1,mod = 1e9+7;int T,n,m,f[N],mu[N],F[N],pre[N],inv[N];int primes[N],len = 0;bitset<N>st;inline int qpow(int base,int e){ int res = 1; while(e){ if(e&1){ res = res*base%mod; } base = base*base%mod; e>>=1; } return res;}void init(){ f[0] = 0,f[1] = 1; for(int i = 2;i<N;++i){ f[i] = (f[i-1]+f[i-2])%mod; } mu[1] = 1; for(int i = 2;i<N;++i){ if(!st[i]){ primes[++len] = i; mu[i] = -1; } for(int j = 1;i*primes[j]<N;++j){ st[i*primes[j]] = true; if(i%primes[j] == 0){ break; } mu[i*primes[j]] = -mu[i]; } } for(int i = 1;i<N;++i){ F[i] = 1; } for(int g = 1;g<N;++g){ for(int T = g;T<N;T+=g){ int val = mu[T/g]; if(val == 1){ F[T] = F[T]*f[g]%mod; }else if(val == -1){ F[T] = F[T]*qpow(f[g],mod-2)%mod; } } } pre[0] = 1; for(int i = 1;i<N;++i){ pre[i] = pre[i-1]*F[i]%mod; } inv[N-1] = qpow(pre[N-1],mod-2); for(int i = N-2;i>=0;--i){ inv[i] = inv[i+1]*F[i+1]%mod; }}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); init(); cin >> T; while(T--){ cin >> n >> m; if(n>m){ swap(n,m); } int res = 1; for(int l = 1,r;l<=n;l = r+1){ r = min({n,n/(n/l),m/(m/l)}); res = res*qpow(pre[r]%mod*inv[l-1]%mod,(n/l)*(m/l))%mod; } cout << res << '\n'; } return 0;}```:::
## [[SDOI2014] 数表](https://www.luogu.com.cn/problem/P3312)
### 题意
29 行未改动考虑如何计算 $F(T)$。
一个很显然的思路是把所有的询问都离线下来,按 $a$ 升序排序。所以我们可以对每一个 $\sigma(g)$ 在 $(a_{i-1},a_i]$ 之间的 $g$ 枚举倍数 $T$ 然后直接加,用树状数组维护即可(单点加,区间求和)。但是“枚举合法的 $g$”这一步是 $O(n)$ 的,这会导致崩溃,我们需要更优的方法。
我们发现我们可以将所有二元组 $(\sigma(g),g)$ 按第一维升序排序,然后我们维护一个指针就好了。时间复杂度 $O(Q \sqrt n \log n + n \ln n)$。我们发现我们可以将所有二元组 $(\sigma(g),g)$ 按第一维升序排序,然后我们维护一个指针就好了。最后是一个树状数组单点加。时间复杂度 $O(Q \sqrt n \log n + n \log^2 n)$。
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define int long longusing namespace std;constexpr int N = 1e5+1,mod = 1ll<<31;int T,mu[N],sigma[N],pe[N],ans[N];struct node{ int n,m,a,id;}que[N];pair<int,int>pii[N];inline bool cmp(const node &x,const node &y){ return x.a<y.a;}int primes[N],len = 0;bitset<N>st;void init(){ mu[1] = sigma[1] = pe[1] = 1; for(int i = 2;i<N;++i){ if(!st[i]){ primes[++len] = i; mu[i] = -1; sigma[i] = pe[i] = i+1; } for(int j = 1;i*primes[j]<N;++j){ st[i*primes[j]] = true; if(i%primes[j] == 0){ pe[i*primes[j]] = pe[i]*primes[j]+1; sigma[i*primes[j]] = sigma[i]/pe[i]*pe[i*primes[j]]; break; } pe[i*primes[j]] = primes[j]+1; sigma[i*primes[j]] = sigma[i]*sigma[primes[j]]; mu[i*primes[j]] = -mu[i]; } }}namespace BIT{ int tree[N]; inline int lowbit(const int &x){ return x&-x; } inline void add(const int &x,const int &y){ for(int i = x;i<N;i+=lowbit(i)){ tree[i] = (tree[i]+y)%mod; } } inline int query(const int &x){ int sum = 0; for(int i = x;i;i^=lowbit(i)){ sum = (sum+tree[i])%mod; } return sum; }}using namespace BIT;signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); init(); for(int i = 1;i<N;++i){ pii[i].first = sigma[i]; pii[i].second = i; } sort(pii+1,pii+N); cin >> T; for(int i = 1;i<=T;++i){ cin >> que[i].n >> que[i].m >> que[i].a; que[i].id = i; } sort(que+1,que+T+1,cmp); int pos = 0; for(int i = 1;i<=T;++i){ while(pos<N-1&&pii[pos+1].first<=que[i].a){ ++pos; for(int j = pii[pos].second;j<N;j+=pii[pos].second){ add(j,(pii[pos].first%mod*mu[j/pii[pos].second]%mod+mod)%mod); } } if(que[i].n>que[i].m){ swap(que[i].n,que[i].m); } int res = 0; for(int l = 1,r;l<=que[i].n;l = r+1){ r = min(que[i].n/(que[i].n/l),que[i].m/(que[i].m/l)); res = (res+(que[i].n/l)*(que[i].m/l)%mod*((query(r)-query(l-1)+mod)%mod)%mod)%mod; } ans[que[i].id] = res; } for(int i = 1;i<=T;++i){ cout << ans[i] << '\n'; } return 0;}```:::
## [P3768 简单的数学题](https://www.luogu.com.cn/problem/P3768)
### 题意
36 行未改动$$
$g,h$ 都是可以 $O(1)$ 计算前缀和的。所以这题就做完了。
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define ll long longusing namespace std;constexpr int N = 4641589;ll mod,n,inv2,inv6;int phi[N];ll F[N];int primes[N],len = 0;bitset<N>st;inline ll qpow(int base,ll e){ ll res = 1; while(e){ if(e&1){ res = res*base%mod; } base = 1ll*base*base%mod; e>>=1; } return res;}void init(){ phi[1] = 1; for(int i = 2;i<N;++i){ if(!st[i]){ primes[++len] = i; phi[i] = (i-1)%mod; } for(int j = 1;i*primes[j]<N;++j){ st[i*primes[j]] = true; if(i%primes[j] == 0){ phi[i*primes[j]] = phi[i]*primes[j]%mod; break; } phi[i*primes[j]] = phi[i]*phi[primes[j]]%mod; } } for(int i = 1;i<N;++i){ F[i] = i%mod*i%mod*phi[i]%mod; F[i] = (F[i]+F[i-1])%mod; }}inline ll calc1(ll n){ return n%mod*(n+1)%mod*inv2%mod;}inline ll calc2(ll n){ return n%mod*(n+1)%mod*(2*n%mod+1)%mod*inv6%mod;}map<ll,ll>mp;ll SumF(ll n){ if(n<N){ return F[n]; }else if(mp.count(n)){ return mp[n]; } ll ans = calc1(n)*calc1(n)%mod; for(ll l = 2,r;l<=n;l = r+1){ r = n/(n/l); ans = (ans-(calc2(r)-calc2(l-1)+mod)%mod*SumF(n/l)%mod+mod)%mod; } return mp[n] = ans;}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin >> mod >> n; inv2 = qpow(2,mod-2); inv6 = qpow(6,mod-2); init(); ll ans = 0; for(ll l = 1,r;l<=n;l = r+1){ r = n/(n/l); ans = (ans+calc1(n/l)*calc1(n/l)%mod*((SumF(r)-SumF(l-1)+mod)%mod)%mod)%mod; } cout << ans; return 0;}```:::
## [P2424 约数和](https://www.luogu.com.cn/problem/P2424)
### 题意
6 行未改动### 解析
我们首先把这个东西拆成差分,这样下标就从 $1$ 开始了。
只需计算 $f(x) = \sum_{i=1}^x \sigma(i)$。只需计算 $f(n) = \sum_{i=1}^n \sigma(i)$。
我们对 $f(x)$ 做如下变换:我们对 $f(n)$ 做如下变换:
$$\begin{aligned}\sum_{i=1}^n \sigma(i)2 行未改动&= \sum_{d=1}^n d \lfloor \frac{n}{d} \rfloor\end{aligned}$$
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define ll long longusing namespace std;int x,y;ll f(int n){ ll ans = 0; for(ll l = 1,r;l<=n;l = r+1){ r = n/(n/l); ans+=(l+r)*(r-l+1)/2*(n/l); } return ans;}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin >> x >> y; cout << f(y)-f(x-1); return 0;}```:::
## [[POI 2007] ZAP-Queries](https://www.luogu.com.cn/problem/P3455)
### 题意
19 行未改动$$
然后数论分块即可。
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define ll long longusing namespace std;constexpr int N = 5e4+1;int T,a,b,g;int mu[N];ll premu[N];int primes[N],len = 0;bitset<N>st;void init(){ mu[1] = 1; for(int i = 2;i<N;++i){ if(!st[i]){ primes[++len] = i; mu[i] = -1; } for(int j = 1;i*primes[j]<N;++j){ st[i*primes[j]] = true; if(i%primes[j] == 0){ break; } mu[i*primes[j]] = -mu[i]; } } for(int i = 1;i<N;++i){ premu[i] = premu[i-1]+mu[i]; }}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); init(); cin >> T; while(T--){ cin >> a >> b >> g; if(a>b){ swap(a,b); } ll res = 0,n = a/g,m = b/g; for(ll l = 1,r;l<=n;l = r+1){ r = min(n/(n/l),m/(m/l)); res+=(premu[r]-premu[l-1])*(n/l)*(m/l); } cout << res << '\n'; } return 0;}```:::
## [P5221 Product](https://www.luogu.com.cn/problem/P5221)
### 题意
给定正整数 $n$,计算
$$\prod_{i=1}^n \prod_{j=1}^n \frac{\operatorname{lcm(i,j)}}{\gcd(i,j)}\prod_{i=1}^n \prod_{j=1}^n \frac{\operatorname{lcm}(i,j)}{\gcd(i,j)}$$
对 $104857601$ 取模,一个质数。
2 行未改动我们对原式做如下转化:
$$\begin{aligned}\prod_{i=1}^n \prod_{j=1}^n \frac{\operatorname{lcm(i,j)}}{\gcd(i,j)}\prod_{i=1}^n \prod_{j=1}^n \frac{\operatorname{lcm}(i,j)}{\gcd(i,j)}&= \prod_{i=1}^n \prod_{j=1}^n \frac{ij}{\gcd^2(i,j)} \\&= \frac{\prod_{i=1}^n \prod_{j=1}^n ij}{\prod_{g=1}^n (g^2)^{\sum_{i=1}^n \sum_{j=1}^n [\gcd(i,j) = g]}} \\&= \frac{(n!)^{2n}}{\prod_{g=1}^n (g^2)^{\sum_{d=1}^{\lfloor \frac{n}{g} \rfloor} \mu(d) \lfloor \frac{n}{dg} \rfloor^2}} \\&= \frac{(n!)^{2n}}{\prod_{T=1}^n \prod_{g \mid T} (g^2)^{\mu(\frac{T}{g}) \lfloor \frac{n}{T} \rfloor^2}}9 行未改动我们发现 $F(T)$ 可以 $O(n \ln n)$ 预处理,所以这题就做完了。
注意卡常。
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define ll long longusing namespace std;constexpr int N = 1e6+1,mod = 104857601;int n;inline int qpow(int base,int e){ int res = 1; while(e){ if(e&1){ res = 1ll*res*base%mod; } base = 1ll*base*base%mod; e>>=1; } return res;}int mu[N],F[N],preF[N],invF[N],inv[N];int primes[N],len = 0;bitset<N>st;void init(){ mu[1] = inv[1] = 1; for(int i = 2;i<=n;++i){ inv[i] = 1ll*(mod-mod/i)*inv[mod%i]%mod; } for(int i = 2;i<=n;++i){ if(!st[i]){ primes[++len] = i; mu[i] = -1; } for(int j = 1;i*primes[j]<=n;++j){ st[i*primes[j]] = true; if(i%primes[j] == 0){ break; } mu[i*primes[j]] = -mu[i]; } } for(int i = 1;i<=n;++i){ F[i] = 1; } for(ll g = 1;g<=n;++g){ for(int T = g;T<=n;T+=g){ if(mu[T/g] == 1){ F[T] = 1ll*F[T]*g%mod*g%mod; }else if(mu[T/g] == -1){ F[T] = 1ll*F[T]*inv[g]%mod*inv[g]%mod; } } } preF[0] = 1; for(int i = 1;i<=n;++i){ preF[i] = 1ll*preF[i-1]*F[i]%mod; } invF[n] = qpow(preF[n],mod-2); for(int i = n-1;i>=0;--i){ invF[i] = 1ll*invF[i+1]*F[i+1]%mod; }}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin >> n; init(); int ans = 1; for(int i = 1;i<=n;++i){ ans = 1ll*ans*i%mod; } ans = qpow(ans,2*n); for(int l = 1,r;l<=n;l = r+1){ r = n/(n/l); ans = 1ll*ans*qpow(qpow(1ll*preF[r]*invF[l-1]%mod,1ll*(n/l)*(n/l)%(mod-1)),mod-2)%mod; } cout << ans; return 0;}```:::
## [P4450 双亲数](https://www.luogu.com.cn/problem/P4450)
同 [[POI 2007] ZAP-Queries](https://www.luogu.com.cn/problem/P3455)。
37 行未改动- $F(1) = 1$- $F(p) = 1-p$- $F(p^k) = F(p)(k \geq 2)$
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define ll long longusing namespace std;constexpr int N = 1e7+1,mod = 20101009;int n,m;int inv[N],F[N];int primes[N],len = 0;bitset<N>st;void init(){ inv[1] = F[1] = 1; for(int i = 2;i<=max(m,6);++i){ inv[i] = 1ll*(mod-mod/i)*inv[mod%i]%mod; } for(int i = 2;i<=m;++i){ if(!st[i]){ primes[++len] = i; F[i] = (1-i+mod)%mod; } for(int j = 1;i*primes[j]<=m;++j){ st[i*primes[j]] = true; if(i%primes[j] == 0){ F[i*primes[j]] = F[i]; break; } F[i*primes[j]] = 1ll*F[i]*F[primes[j]]%mod; } } for(int i = 1;i<=m;++i){ F[i] = 1ll*F[i]*i%mod; F[i] = (F[i]+F[i-1])%mod; }}inline int calc1(int n){ return 1ll*n*(n+1)%mod*inv[2]%mod;}inline int calc2(int n){ return 1ll*n*(n+1)%mod*(2*n+1)%mod*inv[6]%mod;}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin >> n >> m; if(n>m){ swap(n,m); } init(); int res = 0; for(int l = 1,r;l<=n;l = r+1){ r = min(n/(n/l),m/(m/l)); res = (res+1ll*calc1(n/l)*calc1(m/l)%mod*((F[r]-F[l-1]+mod)%mod)%mod)%mod; } cout << res; return 0;}```:::
## [P4449 于神之怒加强版](https://www.luogu.com.cn/problem/P4449)
### 题意
21 行未改动$$
这题能 $O(n \ln n)$,就不继续优化了。
:::success[AC code]```cpp line-numbers#include<bits/stdc++.h>#define ll long longusing namespace std;constexpr int N = 5e6+1,mod = 1e9+7;int t,k,n,m;int primes[N],len = 0;int mu[N],idk[N],F[N];bitset<N>st;inline int qpow(int base,int e){ int res = 1; while(e){ if(e&1){ res = 1ll*res*base%mod; } base = 1ll*base*base%mod; e>>=1; } return res;}void init(){ mu[1] = idk[1] = 1; for(int i = 2;i<N;++i){ if(!st[i]){ primes[++len] = i; mu[i] = mod-1; idk[i] = qpow(i,k); } for(int j = 1;i*primes[j]<N;++j){ st[i*primes[j]] = true; idk[i*primes[j]] = 1ll*idk[i]*idk[primes[j]]%mod; if(i%primes[j] == 0){ break; } mu[i*primes[j]] = (-mu[i]+mod)%mod; } } for(int g = 1;g<N;++g){ for(int T = g;T<N;T+=g){ F[T] = (F[T]+1ll*idk[g]*mu[T/g]%mod+mod)%mod; } } for(int i = 1;i<N;++i){ F[i] = (F[i]+F[i-1])%mod; }}signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin >> t >> k; init(); while(t--){ cin >> n >> m; if(n>m){ swap(n,m); } int 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*((F[r]-F[l-1]+mod)%mod)%mod)%mod; } cout << res << '\n'; } return 0;}```:::
## [P4917 天守阁的地板](https://www.luogu.com.cn/problem/P4917)
### 题意
15 行未改动