太菜了,刷刷NOIP题玩玩。
今天的题好像以前有做过(雾)
A.
#include<bits/stdc++.h> typedef long long ll; int n,q,phi,p[210],cnt; ll x; inline ll sqr(ll x){return x*x;} ll fpow(ll x,ll p){ ll ans=1; for(;p;p>>=1,x=x*x%n)if(p&1)ans=(ans*x)%n; return ans; } inline ll read(){ ll f=1,x=0;char ch; do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9'); do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9'); return f*x; } int main(){ n=read();q=read();phi=n;int qwq=n; for(int i=2;i*i<=n;i++){ if(n%i==0)phi=phi/i*(i-1); while(n%i==0)n/=i; } if(n!=1)phi=phi/n*(n-1); p[cnt=1]=1;n=qwq; for(int i=2;i*i<=n;i++)if(phi%i==0){p[++cnt]=i;if(i*i!=phi)p[++cnt]=phi/i;} while(q--){ x=read();char ch='1'; if(fpow(x,phi)!=1){putchar('0');continue;} for(int j=1;j<=cnt;j++)if(fpow(x,p[j])==1){ch='0';break;} putchar(ch); } }
B.
#include<bits/stdc++.h> #define N 100010 const int yql=1e9+7; typedef long long ll; using namespace std; struct Edge{int u,v,next;}G[2*N]; int tot=0,head[4*N],fa[N],n; ll ans,w[N],sumv[N]; void addedge(int u,int v){ G[++tot].u=u;G[tot].v=v;G[tot].next=head[u];head[u]=tot; G[++tot].u=v;G[tot].v=u;G[tot].next=head[v];head[v]=tot; } inline ll read(){ int f=1,x=0;char ch; do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9'); do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9'); return f*x; } void dfs(int u,int f){ for(int i=head[u];i;i=G[i].next){ int v=G[i].v;if(v==f)continue; fa[v]=u;dfs(v,u); sumv[u]=(sumv[u]+sumv[v])%yql; } ll tmp=(sumv[u]*2LL+w[u])%yql*w[u]%yql; for(int i=head[u];i;i=G[i].next){ int v=G[i].v;if(v==f)continue; tmp=(tmp+(sumv[u]+yql-sumv[v])%yql*sumv[v])%yql; } //printf("%lld\n",tmp); ans=(ans+tmp*w[u])%yql; sumv[u]=(sumv[u]+w[u])%yql; } int main(){ n=read();w[1]=read(); for(int i=2;i<=n;i++){ int u=read();w[i]=read(); i[w]%=yql; addedge(u,i); } dfs(1,0); //for(int i=1;i<=n;i++)printf("%lld ",sumv[i]);puts(""); printf("%lld\n",ans%yql); return 0; }
C.
#include<bits/stdc++.h> const int N=200010; using namespace std; int n,m,fa[N],cnt=0; map<string,int> mps; struct Edge{int u,v,w;}G[N]; char s[100],p[100]; bool operator <(Edge x,Edge y){return x.w<y.w;} inline int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);} inline int read(){ int f=1,x=0;char ch; do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9'); do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9'); return f*x; } int main(){ n=read();m=read(); for(int i=1;i<=m;i++){ scanf("%d%s%s",&G[i].w,s,p); string qwq=string(s); if(mps[qwq]==0)mps[qwq]=++cnt; G[i].u=mps[qwq]; qwq=string(p); if(mps[qwq]==0)mps[qwq]=++cnt; G[i].v=mps[qwq]; } for(int i=1;i<=cnt;i++)fa[i]=i; sort(G+1,G+m+1); for(int i=1;i<=m&&n;i++){ int x=find(G[i].u),y=find(G[i].v); if(x!=y){fa[x]=y;--n;printf("%d\n",G[i].w);} } for(int i=1;i<=n;i++)puts("INF"); }