forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1143Data Bugs.cpp
More file actions
51 lines (45 loc) · 1014 Bytes
/
1143Data Bugs.cpp
File metadata and controls
51 lines (45 loc) · 1014 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
#include <iostream>
#include <vector>
using namespace std;
long gcd(long a, long b)
{
return a % b ? gcd(b, a % b) : b;
}
long lcm(long a, long b)
{
return a / gcd(a,b) * b;
}
class computer {
public:
int y, a, b, d;
};
int n;
void Run() {
vector<computer> com;
for (int i = 0; i < n; ++i) {
computer tmp;
cin >> tmp.y >> tmp.a >> tmp.b;
tmp.d = tmp.b - tmp.a;
com.push_back(tmp);
}
int year = com[0].y, interval = com[0].d;
for (int i = 1; i < n; ++i) {
while (year < com[i].y) year += interval;
while (year % com[i].d != com[i].y % com[i].d && year < 10000) year += interval;
if (year >= 10000) {
cout << "Unknown bugs detected." << endl;
return;
}
interval = lcm(interval, com[i].d);
}
cout << "The actual year is " << year << "." << endl;
}
int main() {
int kase = 0;
while (cin >> n && n) {
cout << "Case #" << ++kase << ":" << endl;
Run();
cout << endl;
}
return 0;
}