Amber
训练做的题里有板子单独拉出来。 欧拉筛 1 int vis[N+5],prim[N+5]; 2 int cnt; 3 void Eular() 4 { 5 vis[0]=vis[1]=1; 6 for(int i=0;i<N;i++) 7 if(!vis[i]) 8 { 9 prim[cnt++]=i; 10 for(ll j=(ll)i*i;j<N;j+=i) vis[j]=1; 11 } 12 } View Code 辗转相除法求逆元 1 ll ans,re; 2 void e_gcd(ll a,ll b) 3 { 4 if(b==0) 5 { 6 ans=1,re=0; 7 return; 8 } 9 e_gcd(b,a%b); 10 ll temp=ans; 11 ans=re; ///*** 12 re=temp-a/b*re; 13 } View Code SPFA找环【bfs 1 int vis[N]; 2 bool spfa_bfs() 3 { 4 ans[s]=v; 5 vis[s]=1; 6 queue<int> qu; 7 qu.push(s); 8 while(!qu.empty()) 9 { 10 int node=qu.front(); 11 qu.pop(); 12 vis[node]=0; 13 for(int i=1;i<=n;i++) 14 {