#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod = 1e9 + 7;
int n;
int pr[15] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
struct num{
int val;
int lowbit;
int rem;
}a[2005];
bool cmp(num a, num b){return a.rem < b.rem;}
void input(){
scanf("%d",&n);
for (int i=1; i<=n; i++) {
scanf("%d",&a[i].val);
int t = a[i].val;
for (int j=0; j<15; j++) {
while(t % pr[j] == 0){
a[i].lowbit |= 1<<j;
t /= pr[j];
}
}
a[i].rem = t;
}
sort(a+1,a+n+1,cmp);
}
int dp[2][1<<15];
int main(){
input();
dp[0][0] = 1;
int back[1<<15];
for (int i=1; i<=n; i++) {
if(a[i].rem == 1){
for (int j=0; j<(1<<15); j++) {
dp[i%2][j] = 0;
if((a[i].lowbit & ~j) == 0){
dp[i%2][j] = dp[(i-1)%2][j ^ a[i].lowbit];
}
dp[i%2][j] += dp[(i-1)%2][j];
dp[i%2][j] %= mod;
}
}
else{
if(a[i].rem != a[i-1].rem){
memcpy(back,dp[(i-1)%2],sizeof(back));
}
for (int j=0; j<(1<<15); j++) {
dp[i%2][j] = 0;
if((a[i].lowbit & ~j) == 0){
dp[i%2][j] = back[j ^ a[i].lowbit];
}
dp[i%2][j] += dp[(i-1)%2][j];
dp[i%2][j] %= mod;
}
}
}
int ret = mod - n - 1;
for (int i=0; i<(1<<15); i++) {
ret += dp[n%2][i];
ret %= mod;
}
printf("%d",ret);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1372 KB |
Output is correct |
2 |
Correct |
0 ms |
1368 KB |
Output is correct |
3 |
Correct |
0 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1368 KB |
Output is correct |
5 |
Correct |
2 ms |
1372 KB |
Output is correct |
6 |
Correct |
2 ms |
1372 KB |
Output is correct |
7 |
Correct |
2 ms |
1368 KB |
Output is correct |
8 |
Correct |
2 ms |
1372 KB |
Output is correct |
9 |
Correct |
0 ms |
1368 KB |
Output is correct |
10 |
Correct |
0 ms |
1372 KB |
Output is correct |
11 |
Correct |
4 ms |
1368 KB |
Output is correct |
12 |
Correct |
3 ms |
1372 KB |
Output is correct |
13 |
Correct |
0 ms |
1368 KB |
Output is correct |
14 |
Correct |
1 ms |
1368 KB |
Output is correct |
15 |
Correct |
0 ms |
1368 KB |
Output is correct |
16 |
Correct |
0 ms |
1368 KB |
Output is correct |
17 |
Correct |
0 ms |
1368 KB |
Output is correct |
18 |
Correct |
0 ms |
1372 KB |
Output is correct |
19 |
Correct |
2 ms |
1368 KB |
Output is correct |
20 |
Correct |
0 ms |
1372 KB |
Output is correct |
21 |
Correct |
0 ms |
1368 KB |
Output is correct |
22 |
Correct |
0 ms |
1368 KB |
Output is correct |
23 |
Correct |
0 ms |
1368 KB |
Output is correct |
24 |
Correct |
3 ms |
1372 KB |
Output is correct |
25 |
Correct |
3 ms |
1372 KB |
Output is correct |
26 |
Correct |
0 ms |
1372 KB |
Output is correct |
27 |
Correct |
3 ms |
1364 KB |
Output is correct |
28 |
Correct |
3 ms |
1368 KB |
Output is correct |
29 |
Correct |
4 ms |
1372 KB |
Output is correct |
30 |
Correct |
4 ms |
1372 KB |
Output is correct |
31 |
Correct |
0 ms |
1372 KB |
Output is correct |
32 |
Correct |
1 ms |
1368 KB |
Output is correct |
33 |
Correct |
0 ms |
1368 KB |
Output is correct |
34 |
Correct |
0 ms |
1372 KB |
Output is correct |
35 |
Correct |
3 ms |
1368 KB |
Output is correct |
36 |
Correct |
4 ms |
1368 KB |
Output is correct |
37 |
Correct |
0 ms |
1368 KB |
Output is correct |
38 |
Correct |
0 ms |
1368 KB |
Output is correct |
39 |
Correct |
0 ms |
1372 KB |
Output is correct |
40 |
Correct |
3 ms |
1364 KB |
Output is correct |
41 |
Correct |
3 ms |
1368 KB |
Output is correct |
42 |
Correct |
4 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
0 ms |
1368 KB |
Output is correct |
3 |
Correct |
0 ms |
1368 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
0 ms |
1372 KB |
Output is correct |
6 |
Correct |
2 ms |
1368 KB |
Output is correct |
7 |
Correct |
2 ms |
1368 KB |
Output is correct |
8 |
Correct |
2 ms |
1372 KB |
Output is correct |
9 |
Correct |
2 ms |
1368 KB |
Output is correct |
10 |
Correct |
0 ms |
1372 KB |
Output is correct |
11 |
Correct |
2 ms |
1364 KB |
Output is correct |
12 |
Correct |
3 ms |
1368 KB |
Output is correct |
13 |
Correct |
3 ms |
1372 KB |
Output is correct |
14 |
Correct |
3 ms |
1372 KB |
Output is correct |
15 |
Correct |
0 ms |
1372 KB |
Output is correct |
16 |
Correct |
4 ms |
1368 KB |
Output is correct |
17 |
Correct |
3 ms |
1368 KB |
Output is correct |
18 |
Correct |
4 ms |
1364 KB |
Output is correct |
19 |
Correct |
4 ms |
1368 KB |
Output is correct |
20 |
Correct |
4 ms |
1364 KB |
Output is correct |
21 |
Correct |
4 ms |
1368 KB |
Output is correct |
22 |
Correct |
4 ms |
1368 KB |
Output is correct |
23 |
Correct |
4 ms |
1368 KB |
Output is correct |
24 |
Correct |
4 ms |
1368 KB |
Output is correct |
25 |
Correct |
5 ms |
1368 KB |
Output is correct |
26 |
Correct |
5 ms |
1372 KB |
Output is correct |
27 |
Correct |
2 ms |
1368 KB |
Output is correct |
28 |
Correct |
5 ms |
1372 KB |
Output is correct |
29 |
Correct |
6 ms |
1372 KB |
Output is correct |
30 |
Correct |
5 ms |
1368 KB |
Output is correct |
31 |
Correct |
3 ms |
1368 KB |
Output is correct |
32 |
Correct |
6 ms |
1372 KB |
Output is correct |
33 |
Correct |
6 ms |
1368 KB |
Output is correct |
34 |
Correct |
6 ms |
1368 KB |
Output is correct |
35 |
Correct |
6 ms |
1364 KB |
Output is correct |
36 |
Correct |
6 ms |
1368 KB |
Output is correct |
37 |
Correct |
7 ms |
1368 KB |
Output is correct |
38 |
Correct |
7 ms |
1364 KB |
Output is correct |
39 |
Correct |
7 ms |
1368 KB |
Output is correct |
40 |
Correct |
7 ms |
1368 KB |
Output is correct |
41 |
Correct |
7 ms |
1372 KB |
Output is correct |
42 |
Correct |
7 ms |
1368 KB |
Output is correct |
43 |
Correct |
7 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
114 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
152 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |