-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber_of_Sequences.cpp
More file actions
69 lines (59 loc) · 1.05 KB
/
number_of_Sequences.cpp
File metadata and controls
69 lines (59 loc) · 1.05 KB
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
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn = 1e5+7;
int prime[maxn] , single_prime_factor[maxn];
int arr[maxn];
const int mod = 1e9+7;
int main()
{
prime[1] = 1;
for(int i = 2; i < maxn; i++)
{
if(prime[i]) continue;
for(int j = 2*i; j < maxn; j += i)
{
prime[j] = 1;
}
for(long long j = 1ll*i*i; j < maxn; j *= i)
{
single_prime_factor[j] = i;
}
}
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> arr[i];
for(int i = 2; i <= n; i++)
{
for(int j = 2*i; j <= n; j += i)
{
if(arr[j] == -1) continue;
int temp_arr = arr[j]%i;
//fix i
if(arr[i] == -1)
arr[i] = temp_arr;
else if(arr[i] != temp_arr)
{
cout << "0\n";
return 0;
}
}
}
long long ans = 1ll;
for(int i = 2;i <= n ; i++)
{
if(arr[i] != -1) continue;
if(prime[i] == 0)
ans = (ans*1ll*i) % mod;
else if(single_prime_factor[i] != 0)
{
ans = (ans * single_prime_factor[i]) %mod;
}
}
cout << ans;
return 0;
}