A - A^B Mod C
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,s=1,c;
cin>>a>>b>>c;
while(b!=0)
{ s%=c;
if(b&1==1)
{ s=s*a;}
s%=c;
a%=c;
a*=a;
a%=c;
b=b>>1;
}
cout<<s;
}
B - 逆元
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll su(ll a)
{
for(ll i=2;i<=sqrt(a);i++)
if(a%i==0)
return 0;
return 1;
}
int main()
{
long long p,s=0;
cin>>p;
if(su(p)==0)cout<<"AKCniubi";
else if(p==2)cout<<1;
else
{ s=(p-1)/2*p;
cout<<s;
}
}
C - 判决素数个数
#include<bits/stdc++.h>
using namespace std;
int *f1= new int[100001];
int *su= new int[10001];
int main()
{ int i,j,k=0,n,m,co=0;
int a,b; cin>>a>>b;
for(i=2;i<=100000;i++)
{
if(f1[i]==0)
{ su[k++]=i;
for(j=i*2;j<=100000;j+=i)
{
f1[j]=1;
}
}
}
if(a>b){swap(a,b);}
co=upper_bound(su,su+k,b)-lower_bound(su,su+k,a);
printf("%d",co);
}
D - 矩阵乘法
#include<bits/stdc++.h>
using namespace std;
int x[1000][1000],y[1000][1000],z[1000][1000];
int main()
{ int a,b,c,i,j,p;
scanf("%d%d%d",&a,&b,&c);
for(i=0;i<a;i++)
{ for(j=0;j<b;j++)
{ scanf("%d",&x[i][j]);
}
}
for(i=0;i<b;i++)
{ for(j=0;j<c;j++)
{ scanf("%d",&y[i][j]);
}
}
for(i=0;i<a;i++)
{ for(j=0;j<c;j++)
{
for(p=0;p<b;p++)
{z[i][j]=x[i][p]*y[p][j]+z[i][j];
}printf("%d ",z[i][j]);
}
printf("\n");
}
return 0;
}
E - Bash游戏
#include<bits/stdc++.h>
using namespace std;
void bash(int n,int m)
{ if(n%(m+1)==0) cout<<"B"<<endl;
else cout<<"A"<<endl;
}
int main()
{ int n,m,t;cin>>t;
while(t--)cin>>n>>m,bash(n,m);
}
F - 取石子游戏
#include<bits/stdc++.h>
using namespace std;
void bash(int n,int m)
{ if(n%(m+1)==0) cout<<"B"<<endl;
else cout<<"A"<<endl;
}
int main()
{ int n,m,t;cin>>t;
while(t--)cin>>n>>m,bash(n,m);
}
G - Matches Game
#include<bits/stdc++.h>
using namespace std;
void nimm(int n)
{
int a,s=0;
while (n--) scanf("%d",&a),s^=a;
printf("%s\n",s==0?"No":"Yes");
}
int main()
{ int n;
while(cin>>n)nimm(n);
}
H - 互质数的个数(一)
#include<bits/stdc++.h>
using namespace std;
int main()
{ long long n;cin>>n;
long long a,s,i;
while(n--)
{ scanf("%lld",&a);
s=a;
for(i=2;i<=sqrt(a);i++)
{
if(a%i==0)
{ s=s/i*(i-1);
while(a%i==0)
{
a/=i;
}
}
}
if(a>1) s=s/a*(a-1);
printf("%lld\n",s);
}
}
I - Sumdiv
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll *p=new ll[600003];
ll *q=new ll[600003];
ll a,b,s;
ll spow(ll num,ll x);
ll f(ll a,ll n);
int main()
{
cin>>a>>b;
if (a==1) {printf("1\n");return 0;}
ll x=a; int co=0;
for (int i=2;i*i<=x;i++)if (x%i==0) {p[++co]=i;while (x%i==0) {x/=i,q[co]++;}}
if (x>1) p[++co]=x,q[co]=1;
s=1;
for (int i=1;i<=co;i++) {ll m=(ll)(p[i]-1)*(ll)9901; s=s*f(p[i],q[i]*b)%9901;}
cout<<s<<endl;
}
ll spow(ll num,ll x)
{
ll b=num%9901;
ll s=1;
while (x) {if ((x&1)==1) s=(s*b)%9901;x>>=1;b=(b*b)%9901;}
return s%9901;
}
ll f(ll a,ll n)
{
if (n==0) return 1;
if (n&1) return f(a,n/2)*(1+spow(a,(n/2)+1))%9901;
else return (f(a,n/2-1)*(1+spow(a,(n/2)+1))%9901+spow(a,n/2))%9901;
}
J - The Lottery
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
ll *a=new ll[200000];
ll lcm(ll a, ll b);
ll gcd(ll a, ll b);
ll dong();
int main()
{
while(scanf("%lld%lld",&n,&m)!=-1){for(int i=0;i<m;i++)scanf("%lld",&a[i]); printf("%lld\n",n-dong());}
}
ll gcd(ll a, ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a, b)*b;}
ll dong()
{ ll t;
ll k=16;
ll s=0;
a[k++]=-1;
for(int i=0;i<m;i++){t=k;for(int j=16;j<t;j++)a[k++]=lcm(a[i],abs(a[j]))*-1*(a[j]<0?-1:1);}
for(int i=17;i<k;i++)s+=n/a[i];
return s;
}
K - 组合数问题
#include<bits/stdc++.h>
using namespace std;
int a[5000][5000],b[5000][5000],c[5000];
int n,m,co,mod;
void ran();
int main()
{
cin>>co>>mod;ran();
while (co--){ cin>>n>>m; if(m>n)m=n;cout<<b[n][m]<<endl; }
}
void ran()
{ a[0][0] = 1; for (int i = 1;i <= 2000;i++) a[i][0] = 1;
for (int i = 1;i <= 2000;i++)
{ for (int j = 1;j <= i;j++)
{ a[i][j]=(a[i-1][j]+a[i-1][j-1])%mod;
if (a[i][j] == 0) c[j]++;
b[i][j] =b[i][j-1]+c[j];
}
}
}
L - 同余方程
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void niyuan(ll a,ll b,ll &x,ll &y)
{
if(!b) x=1,y=0;
else{
niyuan(b,a%b,y,x);
y-=(a/b)*x;
}
}
int main()
{
ll a,b,x,y;
scanf("%lld%lld",&a,&b);
niyuan(a,b,x,y);
printf("%lld",(x+b)%b);
return 0;
}