File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments