Skip to content

Commit 381b717

Browse files
6064_cain_calendar
1 parent 3d6b7cc commit 381b717

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

6064_cain_calendar/cain.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
/*
5+
Get the number of data
6+
Repeat for the number of data:
7+
Get the data
8+
Check the bigger one among x and y
9+
Put checked bigger one to 'bigger'
10+
Put checked smaller one to 'smaller'
11+
Check and Put bigger's mod value to 'biggerMod'
12+
Check and Put smaller's mod value to 'smallerMod'
13+
Check For all i (0 <= i <= 40,000 / 'biggerMod' + 1) whether ( 'bigger' + i * biggerMod ) mod smallerMod = smaller
14+
If there is an i fullfilling the condition, print bigger + i * biggerMod
15+
Else, print -1
16+
Repeat until ends
17+
*/
18+
19+
int main() {
20+
ios_base::sync_with_stdio(false);
21+
cin.tie(nullptr);
22+
23+
int num_data, M, N, x, y, bigger, biggerMod, smaller, smallerMod;
24+
cin >> num_data;
25+
26+
while (num_data--) {
27+
cin >> M >> N >> x >> y;
28+
if (x > y) {
29+
bigger = x; biggerMod = M;
30+
smaller = y; smallerMod = N;
31+
}
32+
else {
33+
bigger = y; biggerMod = N;
34+
smaller = x; smallerMod = M;
35+
}
36+
int upperLimit = ((M*N) / biggerMod) + 2;
37+
int found, foundIndex = -1;
38+
for (int i = 0; i < upperLimit; ++i) {
39+
found = bigger + i * biggerMod;
40+
if (found % smallerMod == smaller % smallerMod) {
41+
foundIndex = i;
42+
break;
43+
}
44+
}
45+
if (foundIndex == -1)
46+
cout << -1 << '\n';
47+
else
48+
cout << found << '\n';
49+
50+
}
51+
return 0;
52+
}

6064_cain_calendar/cain.exe

121 KB
Binary file not shown.

0 commit comments

Comments
 (0)