数论,CF 1372B. Omkar and Last Class of Math

一、题目

1、题目描述

2、输入输出

2.1输入

2.2输出

3、原题链接

Problem - 1372B - Codeforces


二、解题报告

1、思路分析

考虑 lcm(1, n - 1) = n - 1,所以 我们的答案(a, b) 必须满足 lcm(a, b) <= n - 1

不妨设 a <= b

a * b / gcd = lcm(a, b) <= n - 1

由于 b >= n / 2

故 a <= gcd, 而 a >= gcd,故 b 为 a 的倍数

进而推出 a 是 n 的因子

则有 lcm = a * (n - a)  a = n - a,故lcm 最小,a最大

我们求n 的最大的>= 2的因子即可

2、复杂度

时间复杂度: O(t sqrt(n))空间复杂度:O(1)

3、代码详解

 ​
#include <bits/stdc++.h>
#define sc scanf
using i64 = long long;
using PII = std::pair<int, int>;
constexpr int inf32 = 1e9 + 7;
constexpr i64 inf64 = 1e18 + 7;

// #define DEBUG

void solve()
{
    int n;
    std::cin >> n;

    int maf = 1;
    for (int i = 2; i * i <= n; ++ i) {
        if (n % i == 0) {
            maf = n / i;
            break;
        }
    }
    std::cout << maf << ' ' << (n / maf - 1) * maf << '\n';
}

int main()
{
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
    int _ = 1;
    std::cin >> _;
    while (_--)
        solve();
    return 0;
}

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EQUINOX1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值