正文
增加 62 行删除 62 行
10 行未改动111213141516171819229 行未改动全部展开24925025125225325425525625725825926026126226326426526626726826959 行未改动3293303313323333343353363377 行未改动345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392137 行未改动全部展开5305315325335345355365375385395405 行未改动54654754854955055155255355455555694 行未改动6516526536546556566576586596606615 行未改动66766866967067167267367467567667784 行未改动76276376476576676776876977077177277377477512 行未改动7887897907917927937947957967 行未改动80480580680780880981081181281381441 行未改动85685785885986086186286386486586686786886987087187287387424 行未改动89990090190290390490590690790890991091191212 行未改动9259269279289299309319329339 行未改动9439449459469479489499509519529539549559569579589599609614 行未改动966967968969970971972973974975976147 行未改动全部展开112411251126112711281129113011311132263 行未改动全部展开1396139713981399140014011402140314041405140611 行未改动141814191420142114221423142414251426142714281429143014311432116 行未改动全部展开15491550155115521553155415551556155715581559156015611562156393 行未改动16571658165916601661166216631664166516661667166816691670167116721673167425 行未改动170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729219 行未改动全部展开19491950195119521953195419551956195721 行未改动19791980198119821983198419851986198726 行未改动2014201520162017201820192020202120222 行未改动20252026202720282029203020312032203320342035203610 行未改动**数论函数**指的是定义域为正整数的函数,也可以视为一个序列。# 基础部分$\perp$ 在数论中表示“互质”,例如 $2\perp3$。对于一个序列 $f_n=af_{n-1}+bf_{n-2}$,若 $\gcd(a,b)=1$,则有:$$229 行未改动全部展开freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int a,b;cin>>a>>b;int x0,y0;exgcd(a,x0,b,y0);x0%=b;if(x0<0){x0+=b;}cout<<x0<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}59 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;while(T--){int a,b,c;7 行未改动exgcd(a,x0,b,y0);x0*=w,y0*=w;// cerr<<"x0="<<x0<<" y0="<<y0<<endl;int xMin,xMax,yMin,yMax;int deltaA=a/gcdAB;int deltaB=b/gcdAB;xMin=x0%deltaB;if(xMin<=0){xMin+=deltaB;}yMax=(c-a*xMin)/b;yMin=y0%deltaA;if(yMin<=0){yMin+=deltaA;}xMax=(c-b*yMin)/a;// cerr<<"A="<<a<<" B="<<b<<endl;// cerr<<"ΔA="<<deltaA<<" ΔB="<<deltaB<<endl;// cerr<<"xMax="<<xMax<<" xMin="<<xMin<<" yMax="<<yMax<<" yMin="<<yMin<<endl;if(yMax>0){cout<<(xMax-xMin)/deltaB+1<<' '<<xMin<<' '<<yMin<<' '<<xMax<<' '<<yMax<<'\n';}else{cout<<xMin<<' '<<yMin<<'\n';}}}cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}/*13 18 62 1*/```### exgcd 与同余方程137 行未改动全部展开freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>n;ll L=1;for(int i=1;i<=n;i++){cin>>p[i]>>a[i];L*=p[i];}5 行未改动if(x<0){x+=L;}cout<<x<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}94 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>n;ll L=1;for(int i=1;i<=n;i++){cin>>p[i]>>a[i];L*=p[i];}5 行未改动if(x<0){x+=L;}cout<<x<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}84 行未改动for(int i=2;1ll*i*i<=n;i++){if(n%i==0){ans=ans/i*(i-1);while(n%i==0){n/=i;}}}if(n>1){ans=ans/n*(n-1);}return ans;}int qpow(int base,int n){12 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>P>>a>>b;B=ceil(sqrt(euler(P)));c=qpow(a,B);for(int r=0,powR=1,R=qpow(a,P-2);r<B;r++){7 行未改动}powC=1ll*powC*c%P;}cout<<"no solution\n";cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}41 行未改动for(int q=0,powC=1;q<B;q++){auto &pl=m[powC];if(pl.size()<2){pl.push_back(q);}powC=1ll*c*powC%P;}int x=2147483647;for(int r=0,powA=1;r<B;r++){auto &pl=m[1ll*b*powA%P];for(int q:pl){int x0=(1ll*q*B-r)%P;if(x0<0){continue;}if(qpow(a,x0)==b){x=min(x,x0);}}24 行未改动for(int i=2;1ll*i*i<=n;i++){if(n%i==0){ans=ans/i*(i-1);while(n%i==0){n/=i;}}}if(n>1){ans=ans/n*(n-1);}return ans;}int qpow(int base,int n){12 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);while(true){m.clear();cin>>a>>P>>b;if(a==P&&P==b&&b==0){9 行未改动for(int q=0,powC=1;q<B;q++){auto &pl=m[powC];if(pl.size()<2){pl.push_back(q);}powC=1ll*c*powC%P;}int x=2147483647;for(int r=0,powA=1;r<B;r++){auto &pl=m[1ll*b*powA%P];for(int q:pl){int x0=(1ll*q*B-r)%P;if(x0<0){continue;}if(qpow(a,x0)==b){x=min(x,x0);}}4 行未改动}else{cout<<"No Solution\n";}}cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}147 行未改动全部展开while(T--){scanf("%d %d %d",&n,&m,&p);printf("%d\n",Lucas(n+m,n,p));}/*fclose(stdin);fclose(stdout);*/return 0;}263 行未改动全部展开if(pp>1){p.push_back(pp);pc.push_back(pp);}}long long exLucas(ll n,ll m,ll P){if(n<m){return 0;}vector<int>p,pc;breakDown(P,p,pc);11 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);long long n,m,P;cin>>n>>m>>P;cout<<exLucas(n,m,P)<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}116 行未改动全部展开freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,k;cin>>n>>k;cout<<G(n,k)<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}93 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,m;cin>>n>>m;if(n>m){swap(n,m);}cout<<f(n,m)<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}25 行未改动* 除数函数:$\sigma_k(n)=\sum\limits_{d\mid n}d^k$,$\sigma_0(n)$ 通常记作 $d(n)$ 或 $\tau(n)$,$\sigma_1(n)$ 通常记作 $\sigma(n)$。(`\sigma`)* $d(n)$ 的求法:令 $n=p_1^{c_1}p_2^{c_2}\cdots p_k^{c_k}$,其中 $p_1,p_2,\cdots,p_k$ 均为质数。对于每一个指数 $c_i$ 的更改,都会产生新的因数。每一个 $i$,都有 $c_i+1$ 种选择。显然有:$$d(n)=\prod_{i=1}^k(c_i+1)$$时间复杂度 $\mathcal O\left(\sqrt n\right)$。* 欧拉函数:$\varphi(n)$。(`\varphi`)* 莫比乌斯函数:$$\mu(n)=\begin{cases}1&n=1\\0&\exist d>1,d^2\mid n\\(-1)^k&k\text{ 为 }n\text{ 的本质不同质因子个数}\end{cases}$$$\mu(n)=0$ 即 $n$ 含有平方因子。(`\mu`)同时,除数函数 $d(n)$ 即 $n$ 的因数个数,且 $d(ij)$ 满足:219 行未改动全部展开#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/tree_policy.hpp>using namespace std;typedef long long ll;__gnu_pbds::gp_hash_table<int,ll>mem1,mem2;constexpr const int N=5e6/*1664510*/;ll ans1[N+1],ans2[N+1];ll S1(int n){if(n<=N){21 行未改动for(ll l=2,r=n;l<=n;l=r+1,r=n){ll t=n/l;r=n/t;ans-=(r-l+1ll)*S2(t);}return mem2[n]=ans;}void pre(){static int vis[N+1],prime[N+1],size;26 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);pre();ll T;cin>>T;while(T--){2 行未改动mem1.clear();mem2.clear();cout<<S1(n)<<' '<<S2(n)<<'\n';}cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}```10 行未改动111213141516171819229 行未改动全部展开24925025125225325425525625725825926026126226326426526626726826959 行未改动3293303313323333343353363377 行未改动345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392137 行未改动全部展开5305315325335345355365375385395405 行未改动54654754854955055155255355455555694 行未改动6516526536546556566576586596606615 行未改动66766866967067167267367467567667784 行未改动76276376476576676776876977077177277377477512 行未改动7887897907917927937947957967 行未改动80480580680780880981081181281381441 行未改动85685785885986086186286386486586686786886987087187287387424 行未改动89990090190290390490590690790890991091191212 行未改动9259269279289299309319329339 行未改动9439449459469479489499509519529539549559569579589599609614 行未改动966967968969970971972973974975976147 行未改动全部展开112411251126112711281129113011311132263 行未改动全部展开1396139713981399140014011402140314041405140611 行未改动141814191420142114221423142414251426142714281429143014311432116 行未改动全部展开15491550155115521553155415551556155715581559156015611562156393 行未改动16571658165916601661166216631664166516661667166816691670167116721673167425 行未改动170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729219 行未改动全部展开19491950195119521953195419551956195721 行未改动19791980198119821983198419851986198726 行未改动2014201520162017201820192020202120222 行未改动20252026202720282029203020312032203320342035203610 行未改动**数论函数**指的是定义域为正整数的函数,也可以视为一个序列。# 基础部分$\perp$ 在数论中表示“互质”,例如 $2\perp3$。对于一个序列 $f_n=af_{n-1}+bf_{n-2}$,若 $\gcd(a,b)=1$,则有:$$229 行未改动全部展开freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int a,b;cin>>a>>b;int x0,y0;exgcd(a,x0,b,y0);x0%=b;if(x0<0){x0+=b;}cout<<x0<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}59 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;while(T--){int a,b,c;7 行未改动exgcd(a,x0,b,y0);x0*=w,y0*=w;// cerr<<"x0="<<x0<<" y0="<<y0<<endl;int xMin,xMax,yMin,yMax;int deltaA=a/gcdAB;int deltaB=b/gcdAB;xMin=x0%deltaB;if(xMin<=0){xMin+=deltaB;}yMax=(c-a*xMin)/b;yMin=y0%deltaA;if(yMin<=0){yMin+=deltaA;}xMax=(c-b*yMin)/a;// cerr<<"A="<<a<<" B="<<b<<endl;// cerr<<"ΔA="<<deltaA<<" ΔB="<<deltaB<<endl;// cerr<<"xMax="<<xMax<<" xMin="<<xMin<<" yMax="<<yMax<<" yMin="<<yMin<<endl;if(yMax>0){cout<<(xMax-xMin)/deltaB+1<<' '<<xMin<<' '<<yMin<<' '<<xMax<<' '<<yMax<<'\n';}else{cout<<xMin<<' '<<yMin<<'\n';}}}cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}/*13 18 62 1*/```### exgcd 与同余方程137 行未改动全部展开freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>n;ll L=1;for(int i=1;i<=n;i++){cin>>p[i]>>a[i];L*=p[i];}5 行未改动if(x<0){x+=L;}cout<<x<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}94 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>n;ll L=1;for(int i=1;i<=n;i++){cin>>p[i]>>a[i];L*=p[i];}5 行未改动if(x<0){x+=L;}cout<<x<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}84 行未改动for(int i=2;1ll*i*i<=n;i++){if(n%i==0){ans=ans/i*(i-1);while(n%i==0){n/=i;}}}if(n>1){ans=ans/n*(n-1);}return ans;}int qpow(int base,int n){12 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>P>>a>>b;B=ceil(sqrt(euler(P)));c=qpow(a,B);for(int r=0,powR=1,R=qpow(a,P-2);r<B;r++){7 行未改动}powC=1ll*powC*c%P;}cout<<"no solution\n";cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}41 行未改动for(int q=0,powC=1;q<B;q++){auto &pl=m[powC];if(pl.size()<2){pl.push_back(q);}powC=1ll*c*powC%P;}int x=2147483647;for(int r=0,powA=1;r<B;r++){auto &pl=m[1ll*b*powA%P];for(int q:pl){int x0=(1ll*q*B-r)%P;if(x0<0){continue;}if(qpow(a,x0)==b){x=min(x,x0);}}24 行未改动for(int i=2;1ll*i*i<=n;i++){if(n%i==0){ans=ans/i*(i-1);while(n%i==0){n/=i;}}}if(n>1){ans=ans/n*(n-1);}return ans;}int qpow(int base,int n){12 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);while(true){m.clear();cin>>a>>P>>b;if(a==P&&P==b&&b==0){9 行未改动for(int q=0,powC=1;q<B;q++){auto &pl=m[powC];if(pl.size()<2){pl.push_back(q);}powC=1ll*c*powC%P;}int x=2147483647;for(int r=0,powA=1;r<B;r++){auto &pl=m[1ll*b*powA%P];for(int q:pl){int x0=(1ll*q*B-r)%P;if(x0<0){continue;}if(qpow(a,x0)==b){x=min(x,x0);}}4 行未改动}else{cout<<"No Solution\n";}}cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}147 行未改动全部展开while(T--){scanf("%d %d %d",&n,&m,&p);printf("%d\n",Lucas(n+m,n,p));}/*fclose(stdin);fclose(stdout);*/return 0;}263 行未改动全部展开if(pp>1){p.push_back(pp);pc.push_back(pp);}}long long exLucas(ll n,ll m,ll P){if(n<m){return 0;}vector<int>p,pc;breakDown(P,p,pc);11 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);long long n,m,P;cin>>n>>m>>P;cout<<exLucas(n,m,P)<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}116 行未改动全部展开freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,k;cin>>n>>k;cout<<G(n,k)<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}93 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n,m;cin>>n>>m;if(n>m){swap(n,m);}cout<<f(n,m)<<'\n';cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}25 行未改动* 除数函数:$\sigma_k(n)=\sum\limits_{d\mid n}d^k$,$\sigma_0(n)$ 通常记作 $d(n)$ 或 $\tau(n)$,$\sigma_1(n)$ 通常记作 $\sigma(n)$。(`\sigma`)* $d(n)$ 的求法:令 $n=p_1^{c_1}p_2^{c_2}\cdots p_k^{c_k}$,其中 $p_1,p_2,\cdots,p_k$ 均为质数。对于每一个指数 $c_i$ 的更改,都会产生新的因数。每一个 $i$,都有 $c_i+1$ 种选择。显然有:$$d(n)=\prod_{i=1}^k(c_i+1)$$时间复杂度 $\mathcal O\left(\sqrt n\right)$。* 欧拉函数:$\varphi(n)$。(`\varphi`)* 莫比乌斯函数:$$\mu(n)=\begin{cases}1&n=1\\0&\exist d>1,d^2\mid n\\(-1)^k&k\text{ 为 }n\text{ 的本质不同质因子个数}\end{cases}$$$\mu(n)=0$ 即 $n$ 含有平方因子。(`\mu`)同时,除数函数 $d(n)$ 即 $n$ 的因数个数,且 $d(ij)$ 满足:219 行未改动全部展开#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/tree_policy.hpp>using namespace std;typedef long long ll;__gnu_pbds::gp_hash_table<int,ll>mem1,mem2;constexpr const int N=5e6/*1664510*/;ll ans1[N+1],ans2[N+1];ll S1(int n){if(n<=N){21 行未改动for(ll l=2,r=n;l<=n;l=r+1,r=n){ll t=n/l;r=n/t;ans-=(r-l+1ll)*S2(t);}return mem2[n]=ans;}void pre(){static int vis[N+1],prime[N+1],size;26 行未改动freopen("test.out","w",stdout);*/ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);pre();ll T;cin>>T;while(T--){2 行未改动mem1.clear();mem2.clear();cout<<S1(n)<<' '<<S2(n)<<'\n';}cout.flush();/*fclose(stdin);fclose(stdout);*/return 0;}```