2024.12.28 周六

2024.12.28 周六


Q1. 1100

You are given two integers lr. You need to find positive integers a and b such that the following conditions are simultaneously satisfied:

  • la+br
  • gcd(a,b)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.

  1. 给定一个区间,是否能找到整数 a,b ,使和在区间内且不互质。
  2. 找到最大的偶数 evenn>3 时答案可以为:2,even2。若 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;
}

posted @   Jkke  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示