题解:P14321 「ALFR Round 11」D Adjacent Lifting, Fewest Rounds
Minamoto_soviet · · 题解
首先要发现,这是一道注意力题目,因为输入只有一个
显然这个函数一定是与
整数部分显然是
直接分别对这两种情况尝试即可,因为有个
最后发现 情况1 对了,时间复杂度
放code
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e7+16;
int T,p,n;
int f[N];
void init(){
f[1]=1;
for(int i=2;i<=N-16;i++){
f[i]=f[i-1]*i%p;
}
}
int ksm(int a,int b){
int res=1;
for(;b;b>>=1){
if(b&1)res=res*a%p;
a=a*a%p;
}
return res;
}
signed main()
{
cin>>T>>p;
init();
for(;T;T--){
cin>>n;
int k=n/2;
if(k&1)cout<<(f[n]*ksm(2+k,p-2)%p+k*f[n]%p)%p<<endl;
else cout<<(k*f[n]%p)<<endl;
}
return 0;
}