QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89043#5746. DAG Generationchiranko#AC ✓48ms4164kbC++14811b2023-03-18 15:49:272023-03-18 15:49:29

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-18 15:49:29]
  • 评测
  • 测评结果:AC
  • 用时:48ms
  • 内存:4164kb
  • [2023-03-18 15:49:27]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(l,r) for(int i=l;i<=r;i++)
#define jrep(l,r) for(int j=l;j<=r;j++)
#define clz __builtin_popcount

using namespace std;

typedef long long ll;
const int N=1.2e5,mod=1e9+9,P=100000,inv2=(mod+1)>>1;

int p[N],p2[N];
int fac[N];

int qmi(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=(ll)res*a%mod;
		a=(ll)a*a%mod;
		b>>=1;
	}
	return res;
}

int inv(int a)
{
	return qmi(a,mod-2);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	fac[0]=1;
	rep(1,P)fac[i]=(ll)fac[i-1]*i%mod;
	
	p[1]=1;
	rep(2,P)p[i]=2ll*(mod+1-qmi(inv2,i))*p[i-1]%mod;
	
	int T;cin>>T;
	while(T--)
	{
		int n;cin>>n;
		int res=(ll)qmi(2,(ll)n*(n-1)/2%(mod-1))*fac[n]%mod;
		cout<<(mod+1-(ll)inv(res)*p[n]%mod)%mod<<'\n';
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 3996kb

input:

4
1
2
3
100

output:

0
375000004
117187502
778748905

result:

ok 4 number(s): "0 375000004 117187502 778748905"

Test #2:

score: 0
Accepted
time: 10ms
memory: 4096kb

input:

5
1
2
3
4
5

output:

0
375000004
117187502
213897708
995024095

result:

ok 5 number(s): "0 375000004 117187502 213897708 995024095"

Test #3:

score: 0
Accepted
time: 48ms
memory: 4164kb

input:

100000
64268
66535
9758
42907
84212
83488
27748
86198
80658
11614
93419
2528
96160
79473
83517
43109
37111
46603
93665
54540
84236
62717
24719
57225
8333
15728
40821
31719
13096
75018
76890
46244
75863
59618
67460
10326
84775
11276
83363
72071
9353
94316
9469
3969
78568
53071
96835
50125
2728
46756
...

output:

517835222
425525315
415451955
804144524
465143750
248034271
13166687
703325946
341000020
13797696
905521918
608927142
591090671
501585335
146368913
172358003
116621710
241875456
448868678
155749600
350155635
599343092
400133403
78229211
452768218
582618783
811512224
912730301
470660521
250329917
370...

result:

ok 100000 numbers