File tree 1 file changed +45
-0
lines changed
2022/Contests/Div 3/828/Programs
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < algorithm>
4
+ #include < map>
5
+
6
+ using namespace std ;
7
+
8
+ void solve ()
9
+ {
10
+ long long a, b, c, d;
11
+ cin >> a >> b >> c >> d;
12
+
13
+ long long answer_x = -1 , answer_y = -1 ;
14
+ for (long long x = a + 1 ; x <= c; x++)
15
+ {
16
+ long long complement = (a*b)/__gcd (a*b, x);
17
+ // cout << "X = " << x << " Complement = " << complement << "\n";
18
+
19
+ long long y = complement;
20
+
21
+ for (int i = 1 ; y <= b; i++)
22
+ {
23
+ y = i*complement;
24
+ }
25
+ // cout << "Y = " << y << "\n";
26
+ if (y <= d)
27
+ {
28
+ answer_x = x, answer_y = y;
29
+ break ;
30
+ }
31
+ }
32
+
33
+ cout << answer_x << " " << answer_y << " \n " ;
34
+ }
35
+
36
+ int main ()
37
+ {
38
+ int no_of_test_cases;
39
+ cin >> no_of_test_cases;
40
+
41
+ while (no_of_test_cases--)
42
+ solve ();
43
+
44
+ return 0 ;
45
+ }
You can’t perform that action at this time.
0 commit comments