Skip to content

Commit d4ab249

Browse files
Add files via upload
1 parent 586195b commit d4ab249

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
typedef vector<int> vi;
8+
#define fast_cin() \
9+
ios_base::sync_with_stdio(false); \
10+
cin.tie(NULL); \
11+
cout.tie(NULL);
12+
13+
int main() {
14+
int tc;
15+
cin >> tc;
16+
while (tc--) {
17+
ll l, r, g;
18+
cin >> l >> r >> g;
19+
20+
ll ld = (l + g - 1) / g;
21+
ll rd = r / g;
22+
23+
bool done = false;
24+
for (ll diff = (rd - ld); diff >= 0 && !done; diff--) {
25+
for (ll x = ld; x + diff <= rd; x++) {
26+
if (gcd(x, x + diff) == 1) {
27+
cout << x*g << " " << g*(x + diff) << endl;
28+
done = true;
29+
break;
30+
}
31+
}
32+
}
33+
34+
if (!done) {
35+
cout << -1 << " " << -1 << endl;
36+
}
37+
}
38+
39+
return 0;
40+
}

0 commit comments

Comments
 (0)