-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathantColony.cpp
More file actions
55 lines (45 loc) · 943 Bytes
/
antColony.cpp
File metadata and controls
55 lines (45 loc) · 943 Bytes
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
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
ll gcd (ll a, ll b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
int main ()
{
ll n;
cin >> n;
ll s[n];
for (ll i = 0; i < n; i++) cin >> s[i];
ll t;
cin >> t;
while (t--) {
ll x, y;
cin >> x >> y;
x--;
y--;
ll minim = 100000000000;
ll freq = 0;
for (ll k = x; k <= y; k++) {
if (minim == s[k]) {
freq++;
} else if (minim > s[k]) {
minim = s[k];
freq = 1;
}
}
ll totGCD = s[x];
for (ll j = x+1; j <= y; j++) {
totGCD = gcd(s[j], totGCD);
}
if (totGCD == minim) {
cout << (y-x+1) - freq << "\n";
} else {
cout << (y-x+1) << "\n";
}
}
}