10.4 考试
T1
是一道语文题
随便sort一下就行了
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const ll N=10006;
const ll mod=((ll)1<<31)-1;
ll n;
ll a[N],b[N],c[N];
ll num[N];
ll con;
void lisan()
{
con=0;
sort(b+1,b+1+n);
b[0]=-3132;
for(int i=1;i<=n;++i)
if(b[i]!=b[i-1])
c[++con]=b[i];
int t1,t2;
for(int i=1;i<=con;++i)
{
t1=(i-1==0?con:i-1);
t2=(i==con?1:i+1);
if( (c[t1]+c[i])%mod==c[t2] )
num[i]=1;
else
num[i]=0;
}
}
int er(int l,int r,ll vv)
{
int mid;
while(l<=r)
{
mid=(l+r)>>1;
if(c[mid]==vv)
return mid;
if(c[mid]<vv)
l=mid+1;
else
r=mid-1;
}
}
int main(){
//freopen("T1.in","r",stdin);
int T=0;
while(~scanf("%lld",&n))
{
++T;
for(int i=1;i<=n;++i)
{
scanf("%lld",&a[i]);
b[i]=a[i];
}
//printf("n=%d\n",n);
lisan();
if(con==1)
{
printf("Case #%d: -1\n",T);
continue;
}
int ans=0,temp;
for(int i=1;i<=n;++i)
{
temp=er(1,con,a[i]);
ans+=num[temp];
}
printf("Case #%d: %d\n",T,ans);
}
}
T2
根据 f[i]=(f[i]+n-i+1)%i 递推即可
想法是每次T人后,重新标号,根据这个逆推
#pragma GCC optimize("O3")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=10000006;
int T;
int n;
int main(){
//freopen("T2.in","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int ans=0;
for(int i=1;i<=n;++i)
ans=(ans+n-i+1)%i;
printf("%d\n",ans+1);
}
/*
2
2
3
*/
}
T3
首先指数%phi(p),然后phi(p)是合数,用孙子定理
Lucas求组合数,要预处理阶乘及逆元
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=1000006;
const int mod=54184622;
ll mi(ll a,int ci,int mm)
{
ll ans=1;
while(ci)
{
if(ci&1)
ans=ans*a%mm;
a=a*a%mm;
ci>>=1;
}
return ans%mm;
}
ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
void egcd(ll a,ll b,ll &x,ll &y)
{
if(b==0)
{
x=1;y=0;
return ;
}
egcd(b,a%b,x,y);
ll temp=x;
x=y;
y=temp-a/b*y;
}
int ou(int x)
{
int tt=x;
for(int i=2;i*i<=x;++i)
if(x%i==0)
{
tt=tt-tt/i;
while(x%i==0)
x/=i;
}
if(x!=1)
tt=tt-tt/x;
return tt;
}
int n,g;
ll p[106]={0,2,3,5,7,129011};
ll a[106];
ll jie[7][N],jieni[7][N],ni[7][N];
ll cm(int n,int m,int order)
{
if(n<m)
return 0;
return jie[order][n]*jieni[order][m]%p[order]*jieni[order][n-m]%p[order];
}
ll Lucas(int n,int m,int order)
{
if(m==0)
return 1;
return cm(n%p[order],m%p[order],order)*Lucas(n/p[order],m/p[order],order)%p[order];
}
ll CRT()
{
ll Mi,M=1,ans=0,x,y;
for(int i=1;i<=5;++i)
M*=p[i];
//printf("M=%lld\n",M);
for(int i=1;i<=5;++i)
{
Mi=M/p[i];
egcd(Mi,p[i],x,y);
ans=(ans+Mi*x*a[i]%M)%M;
}
if(ans<0)
ans+=M;
return ans;
}
void chu()
{
for(int i=1;i<=5;++i)
{
ni[i][1]=1;
for(int j=2;j<N;++j)
ni[i][j]=(ll)(p[i]-p[i]/j)*ni[i][p[i]%j]%p[i];
jieni[i][0]=jie[i][0]=1;
for(int j=1;j<N;++j)
{
jie[i][j]=jie[i][j-1]*j%p[i];
jieni[i][j]=jieni[i][j-1]*ni[i][j]%p[i];
}
}
}
int main(){
//freopen("in.in","r",stdin);
chu();
scanf("%d%d",&n,&g);
for(int i=1;i<=n;++i)
{
if( gcd(i,n)==1 )
for(int j=1;j<=5;++j)
a[j]=(a[j]+Lucas(g,i,j))%p[j];
}
printf("%lld",mi(n,CRT(),mod) );
}
暴露出的问题就是我的数学十分薄弱