QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67320 | #5099. 朝圣道 | _ZMF_ | 0 | 0ms | 0kb | C++11 | 2.0kb | 2022-12-10 11:45:58 | 2022-12-10 11:46:01 |
Judging History
answer
#include<bits/stdc++.h>
#include "pilgrimage.h"
using namespace std;
//#define int long long
typedef long long ll;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
if(!b){x=1;y=0;return a;}
ll res=exgcd(b,a%b,x,y),t;
t=x;x=y;y=t-a/b*y;
return res;
}
const int N = 1e6 + 9;
ll p;
vector<int> G;
vector<int> jc[N];
inline ll power(ll a,ll b,ll mod)
{
ll sm;
for(sm=1;b;b>>=1,a=a*a%mod)if(b&1)
sm=sm*a%mod;
return sm;
}
ll fac(ll n,ll pi,ll pk)
{
if(!n)return 1;
ll res=1;
res = res * jc[pi][pk] % pk;
res=power(res,n/pk,pk);
res = res * jc[pi][n % pk] % pk;
return res*fac(n/pi,pi,pk)%pk;
}
inline ll inv(ll n,ll mod)
{
ll x,y;
exgcd(n,mod,x,y);
return (x+=mod)>mod?x-mod:x;
}
inline ll CRT(ll b,ll mod){return b*inv(p/mod,mod)%p*(p/mod)%p;}
const int MAXN=11;
static ll n,m;
static ll w[MAXN];
inline ll C(ll n,ll m,ll pi,ll pk)
{
ll up=fac(n,pi,pk),d1=fac(m,pi,pk),d2=fac(n-m,pi,pk);
ll k=0;
for(register ll i=n;i;i/=pi)k+=i/pi;
for(register ll i=m;i;i/=pi)k-=i/pi;
for(register ll i=n-m;i;i/=pi)k-=i/pi;
return up*inv(d1,pk)%pk*inv(d2,pk)%pk*power(pi,k,pk)%pk;
}
inline ll exlucus(ll n,ll m)
{
ll res=0,pk,tmp=p;
for(auto v : G)
{
int i = v;
pk=1;while(tmp%i==0)pk*=i,tmp/=i;
// cout << i << " " << pk << endl;
(res+=CRT(C(n,m,i,pk),pk))%=p;
}
if(tmp>1)(res+=CRT(C(n,m,tmp,tmp),tmp))%=p;
return res;
}
void init(int o, int p)
{
int tmp = p;
for (int i = 2; i <= tmp; i++)
if(tmp % i == 0)
{
G.push_back(i);
int pk = 1; while(tmp % i == 0) pk *= i, tmp /= i;
jc[i].push_back(1); jc[i].push_back(1); int now = 1;
for (int j = 2; j <= pk; j++)
{
if(j % i) now = now * j % pk;
jc[i].push_back(now);
}
}
return ;
}
int ask(ll n)
{
int inv2 = (p + 1) / 2;
ll ans = n % p; ans = ans * exlucus(n * 2, n) % p;
ans = ans * power(inv2, 2 * n, p) % p;
return (int) ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1 910276 554767 6 10 7 4 10 12 9 3 3 5 7 10 5 6 1 6 3 9 6 8 12 11 8 2 12 5 9 3 8 2 12 11 2 3 4 9 2 5 5 11 6 4 8 11 3 9 2 2 8 9 2 8 9 6 2 9 2 10 10 7 5 6 4 4 11 12 8 8 2 2 4 3 3 5 6 6 8 11 6 9 9 3 4 1 2 2 6 9 9 2 3 2 12 6 1 7 2 4 12 11 4 7 6 3 9 4 6 5 3 3 12 6 2 1 1 7 2 6 5 9 11 6 3 4 11 1 2 4 5 4 10...
output:
Unauthorized output
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #5:
score: 0
Runtime Error
input:
3 1 334547 8234
output:
Unauthorized output
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Runtime Error
Test #8:
score: 0
Runtime Error
input:
6 958477 522361 280121915553826833 734266539148641647 72849162479700582 274266741463686096 60278972064195458 828423669427600612 571432949203039978 518511460268700898 486268614705621285 19216283231217074 611458416727512530 175147354285288662 799769622289998997 400123443628688299 145546980862133838 40...
output:
Unauthorized output
result:
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Runtime Error
Test #33:
score: 0
Runtime Error
input:
8 9963 251 831797004675585320 494759973681332858 701341496127272302 252910460485222469 250965009655458584 366193481309061299 633134388675839346 791999098066205672 196620805863610860 363773642045280947 466508590762410710 407790578717064135 181590911404670570 570642047249889864 70138464625729452 23634...
output:
Unauthorized output
result:
Subtask #9:
score: 0
Skipped
Dependency #2:
0%