2024.12.28 周六
2024.12.28 周六
Q1. 1100
You are given two integers \(l \le r\). You need to find positive integers \(a\) and \(b\) such that the following conditions are simultaneously satisfied:
- \(l \le a + b \le r\)
- \(\gcd(a, b) \neq 1\)
or report that they do not exist.
\(\gcd(a, b)\) denotes the greatest common divisor of numbers \(a\) and \(b\). For example, \(\gcd(6, 9) = 3\), \(\gcd(8, 9) = 1\), \(\gcd(4, 2) = 2\).
------------------------独自思考分割线------------------------
-
一道小数论。
A1.
- 给定一个区间,是否能找到整数 \(a,b\) ,使和在区间内且不互质。
- 找到最大的偶数 \(even\),\(n>3\) 时答案可以为:\(2,even-2\)。若 \(even\) 不在区间内只有一种可能 \(l=r\&\&r为奇数\),这种情况仅当 \(r\) 是合数有解,找因子。
------------------------代码分割线------------------------
A1.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int l, r;
cin >> l >> r;
int a = 2;
int max_even = r & 1 ? r - 1 : r;
int b = max_even - 2;
if (b < 2)
{
cout << -1 << endl;
return;
}
if (l == r && (r & 1))
{
for (int i = 2; i <= r / i; i++)
if (r % i == 0)
{
int k = r / i;
cout << i << ' ' << (k - 1) * i << endl;
return;
}
cout << -1 << endl;
return;
}
cout << a << " " << b << endl;
}

浙公网安备 33010602011771号