-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreetr.cpp
More file actions
46 lines (43 loc) · 834 Bytes
/
streetr.cpp
File metadata and controls
46 lines (43 loc) · 834 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
#include <iostream>
#include <cstring> //memset
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
else return gcd(b, a%b);
}
int main() {
freopen("input.txt", "r", stdin);
int len, prev = 0, curr, i, hcf, res = 0, add;
cin >> len;
int diff[len];
for (i = 0; i < len; i++) {
cin >> curr;
if (i>0)
diff[i-1] = curr-prev;
prev = curr;
}
hcf = gcd(max(diff[0], diff[1]), min(diff[0], diff[1]));
for (i=2; i<len-1; i++) {
hcf = gcd(max(hcf, diff[i]), min(hcf, diff[i]));
}
for (i=0; i<len-1; i++) {
add = diff[i]/hcf - 1;
if (add < 0)
add = 0;
res += add;
}
cout << res << endl;
return 0;
}