-
Notifications
You must be signed in to change notification settings - Fork 0
/
danca.cpp
56 lines (50 loc) · 1.1 KB
/
danca.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
#include <cstdio>
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
using namespace std;
vector < pair <int, int> > v;
int L, I;
int
find (int x) {
for (int i = 0; i < I; i++)
if (v[i].first == x) return 1;
return 0;
}
int
verify (int h) {
for (int i = 1; i < I; i++) {
int x = (v[i].first + v[i].second * h) % L;
if (x == 0 ) x = L;
if (h == 74)
if (i == 49) {
cout << v[i].first << v[i].second << endl << h << endl << x << endl;
}
if (!find (x)) return 0;
}
return 1;
}
int
main () {
int hits = INT_MAX;
cin >> L >> I;
for (int i = 0; i < I; i++ ) {
int x, y;
cin >> x >> y;
v.push_back (make_pair (x, y));
}
cout << verify (75) << endl;
for (int i = 1; i < I; i++) {
int h = (v[i].first - v[0].first) % L;
if (verify (h) && h < hits)
hits = h;
}
if (hits == INT_MAX)
cout << L << endl;
else if (hits < 0)
cout << L + hits << endl;
else
cout << hits << endl;
return 0;
}