[CF] A. LCM Problem - Educational Codeforces Round 92 (Rated for Div. 2)

https://codeforces.com/contest/1389/problem/A

题目大意

给出 $l, r$ 求任意 $x, y$ 使得 $l \le x < y \le r$,$l \le lcm(x, y) \le r$。无解输出 ‘-1 -1’。

$1 \le l < r \le 10^9$。

简要题解

考虑较小的 $x$,$lcm$ 一定比它大,而比他大的最小的 $lcm(x, y) = 2x$。所以我们只要判断最小的 $l$ 对应的 $2l$ 在不在范围里即可。

复杂度

$T$:$O(1)$

$S$:$O(1)$

代码实现

#include <bits/stdc++.h>
using namespace std;

int io_=[](){ ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();

using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
using VI = vector<int>;
using MII = map<int, int>;

template<typename T> void cmin(T &x,const T &y) { if(y<x) x=y; }
template<typename T> void cmax(T &x,const T &y) { if(x<y) x=y; }
template<typename T> bool ckmin(T &x,const T &y) { 
    return y<x ? (x=y, true) : false; }
template<typename T> bool ckmax(T &x,const T &y) { 
    return x<y ? (x=y, true) : false; }
template<typename T> void cmin(T &x,T &y,const T &z) {// x<=y<=z 
    if(z<x) { y=x; x=z; } else if(z<y) y=z; }
template<typename T> void cmax(T &x,T &y,const T &z) {// x>=y>=z
    if(x<z) { y=x; x=z; } else if(y<z) y=z; }

// mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
// mt19937_64 rnd_64(chrono::system_clock::now().time_since_epoch().count());

/*
---------1---------2---------3---------4---------5---------6---------7---------
1234567890123456789012345678901234567890123456789012345678901234567890123456789
*/

void solve() {
  int l, r; cin >> l >> r;

  if (r < l * 2) {
    cout << "-1 -1\n";
  } else {
    cout << l << ' ' << (l * 2) << '\n';
  }
}

int main() {
  int t = 1; 
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Prev: [CF] D. AB-string - Educational Codeforces Round 74 (Rated for Div. 2)
Next: [CF] B. Array Walk - Educational Codeforces Round 92 (Rated for Div. 2)