【快速幂的水题】
暴力算就是了
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#define int long long
using namespace std;
const int MAXN=100010;
const int MOD=1000000007;
map<int,int> G;
inline int qpow(int x,int k){
int s=1;
while(k){
if(k&1) s=s*x%MOD;
k>>=1;
x=x*x%MOD;
}
return s;
}
int fact[MAXN],inv[MAXN];
inline int C(int n,int m){
if(m>n) return 0;
return fact[n]*inv[m]%MOD*inv[n-m]%MOD;
}
int n,q,F[MAXN];
signed main(){
fact[0]=1;
for(int i=1;i<=100000;++i)
fact[i]=fact[i-1]*i%MOD;
inv[100000]=qpow(fact[100000],MOD-2)%MOD;
for(int i=99999;i>=0;--i)
inv[i]=inv[i+1]*(i+1)%MOD;
int T;
scanf("%lld",&T);
while(T--){
scanf("%lld%lld",&n,&q);
G.clear();
for(int i=1;i<=n;++i){
scanf("%lld",&F[i]);
G[F[i]]=i;
}
int x,k;
while(q--){
scanf("%lld%lld",&x,&k);
printf("%lld\n",F[C(k,G[x])%n+1]);
}
}
return 0;
}
用总数减去不符的
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#define int long long
using namespace std;
const int MOD=1000000007;
inline int mul(int x,int k){
int s=0;
while(k){
if(k&1) s=(s+x)%MOD;
k>>=1;
x=(x+x)%MOD;
}
return s;
}
inline int qpow(int x,int k){
int s=1;
while(k){
if(k&1) s=mul(s,x)%MOD;
k>>=1;
x=mul(x,x)%MOD;
}
return s;
}
int n,m;
signed main(){
scanf("%lld%lld",&n,&m);
printf("%lld\n",(qpow(m,n)-mul(m,qpow(m-1,n-1))%MOD+MOD)%MOD);
return 0;
}
暴力计算,对几个MOD取模hash判断
#include<iostream>
#include<cstring>
#include<cstdio>
#define int long long
using namespace std;
const int MOD1=19260817;
const int MOD2=1000000007;
const int MOD3=998244353;
const int MOD4=1000000009;
int T,a,x,b,y;
inline int qpow(int x,int k,int MOD){
int s=1;
while(k){
if(k&1) s=s*x%MOD;
k>>=1;
x=x*x%MOD;
}
return s;
}
signed main()
{
scanf("%lld",&T);
while(T--){
scanf("%lld%lld%lld%lld",&x,&a,&y,&b);
if(qpow(x,a,MOD1)!=qpow(y,b,MOD1)||qpow(x,a,MOD2)!=qpow(y,b,MOD2)
||qpow(x,a,MOD3)!=qpow(y,b,MOD3)||qpow(x,a,MOD4)!=qpow(y,b,MOD4))
puts("No");
else puts("Yes");
}
return 0;
}