-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBob_and_Mathematics.cpp
100 lines (100 loc) · 1.54 KB
/
Bob_and_Mathematics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll N = 1000005;
ll is[N];
ll arr[N];
ll choose[1005][1005];
ll mul(ll a, ll b, ll mod) {return (a * b) % mod;}
ll add(ll a, ll b, ll MOD)
{
a += b;
if(a >= MOD)
{
a -= MOD;
}
if(a < 0)
{
a += MOD;
}
return a;
}
void seive()
{
is[1] = 1;
for(ll i = 2; i < N; i++)
{
if(!is[i])
{
for(ll j = i * i; j < N; j += i)
{
is[j] = 1;
}
}
}
}
void pre(ll MOD)
{
choose[0][0] = 1;
for(int i = 1; i <= 1004; i++)
{
choose[i][0] = 1;
choose[i][1] = i;
}
for(int i = 2; i <= 1004; i++)
{
for(int j = 2; j <= 1004; j++)
{
if(j > i)
{
break;
}
choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1], MOD);
}
}
}
ll power(ll a, ll b, ll mod)
{
if(b == 0) return 1;
if(b == 1) return a % mod;
ll x = power(a, b / 2, mod);
x = mul(x, x, mod);
if(b % 2)
{
return mul(x, a, mod);
}
return x;
}
int main()
{
ll MOD1 = 1000000007;
ll mod2 = 1000000006;
seive();
pre(mod2);
ll T, N, primes, noprimes;
scanf("%lld", &T);
while(T--)
{
primes = noprimes = 0;
scanf("%lld", &N);
for(int i = 0; i < N; i++)
{
scanf("%lld", &arr[i]);
primes += !is[arr[i]];
}
noprimes = N - primes;
ll ans = 1;
ll c = 0;
for(ll i = 0; i <= noprimes; ++i){
c = add(c, choose[noprimes][i], mod2);
}
for(int i = 0; i <= primes; i++)
{
ll possible = mul(c, choose[primes][i], mod2);
ll curr = power(i + 2, possible, MOD1);
ans = mul(ans, curr, MOD1);
}
printf("%lld\n", ans);
}
return 0;
}