版本比较
数论
正文
增加 62 行删除 62 行
10 行未改动11121314151516171819229 行未改动全部展开24925025125225325325425525625725825926026126226326326426526526626726826959 行未改动3293303313323333333343353363377 行未改动345346347348349349350351352352353354355356357358358359360361362362363364365366367368368369370370371372372373374375376376377378378379380381382383384385386387388387388389390391392137 行未改动全部展开5305315325335345345355365365375385395405 行未改动54654754854955055055155255255355455555694 行未改动6516526536546556556566576576586596606615 行未改动66766866967067167167267367367467567667784 行未改动76276376476576676776676776876977077177177277377477512 行未改动7887897907917927927937947957967 行未改动80480580680780880880981081081181281381441 行未改动85685785885986086086186286386486586686786886987087087187287387424 行未改动89990090190290390490390490590690790890890991091191212 行未改动9259269279289299299309319329339 行未改动9439449459469479479489499509519529539549559569579579589599609614 行未改动966967968969970970971972972973974975976147 行未改动全部展开1124112511261127112811281129113011311132263 行未改动全部展开139613971398139914001400140114021402140314041405140611 行未改动141814191420142114221422142314241425142614261427142814281429143014311432116 行未改动全部展开15491550155115521553155315541555155615571557155815591559156015611562156393 行未改动16571658165916601661166116621663166416651666166716681668166916701670167116721673167425 行未改动17001701170217031704170417051706170617071708170917101710171117121713171417151716171617171718171917201721172217231724172517251726172717281729219 行未改动全部展开194919501951195219531953195419551956195721 行未改动197919801981198219831983198419851986198726 行未改动20142015201620172018201820192020202120222 行未改动2025202620272028202920292030203120312032203320342035203610 行未改动**数论函数**指的是定义域为正整数的函数,也可以视为一个序列。
# 基础部分
$\perp$ 在数论中表示“互质”,例如 $2\perp3$。 $\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'; cout<<(xMax-xMin)/deltaB+1<<' '<<xMin<<' '<<yMin<<' '<<xMax<<' '<<yMax<<'\n'; }else{ cout<<xMin<<' '<<yMin<<'\n'; cout<<xMin<<' '<<yMin<<'\n'; } } }
cout.flush();
/*fclose(stdin); fclose(stdout);*/ return 0;}/*13 18 6
2 1 */ 2 1*/```
### exgcd 与同余方程
137 行未改动全部展开 freopen("test.out","w",stdout);*/
ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
cin>>n; ll L=1; 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; 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; } n/=i; } } } if(n>1){ ans=ans/n*(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; } n/=i; } } } if(n>1){ ans=ans/n*(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){ 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; __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;}```