zoukankan      html  css  js  c++  java
  • Codeforces Round #655 (Div. 2) B. Omkar and Last Class of Math(数论)

    In Omkar's last class of math, he learned about the least common multiple, or LCMLCM . LCM(a,b)LCM(a,b) is the smallest positive integer xx which is divisible by both aa and bb .

    Omkar, having a laudably curious mind, immediately thought of a problem involving the LCMLCM operation: given an integer nn , find positive integers aa and bb such that a+b=na+b=n and LCM(a,b)LCM(a,b) is the minimum value possible.

    Can you help Omkar solve his ludicrously challenging math problem?

    Input

    Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤101≤t≤10 ). Description of the test cases follows.

    Each test case consists of a single integer nn (2≤n≤1092≤n≤109 ).

    Output

    For each test case, output two positive integers aa and bb , such that a+b=na+b=n and LCM(a,b)LCM(a,b) is the minimum possible.

    Example

    Input

    Copy

    3

    4

    6

    9

    Output

    Copy

    2 2

    3 3

    3 6

    观察样例+猜测会发现,n为偶数的话直接除以2,奇数的话两个数一定为倍数关系,而若为倍数,又想lcm尽可能小,必须让小的那个数尽可能大。又因为两个数和为n,故较小的那个数是n的最大的那个因子(除去自己)。凭直觉瞎猜的结论,于是转化为找n最大的因子,复杂度根n。

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        cin >> t;
        while(t--)
        {
            int n;
            cin >> n;
            if(n & 1)
            {
                int mmax = 0;
                for(int i = 1; i <= sqrt(n); i++)
                {
                    if(n % i == 0)
                    {
                        mmax = max(mmax, i);
                        if(i != 1) mmax = max(mmax, n / i);
                    }
                }
                cout << n - mmax << ' ' << mmax << endl;
            }
            else
            {
                cout << n/2 << ' ' << n/2 << endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    RAC一个节点自动重启问题分析
    Oracle Audit 审计总结
    oracle 11g日志审计
    在线剪辑歌曲
    转载:MySQL Cluster NDB(Mysql 集群)
    U 盘多系统安装盘制作神器YUMI
    转载:网站限制IP地址访问-精确到国家/省/市IP地址
    开源企业云盘Seafile部署
    K8S(二)-创建一个pod应用
    mariadb升级
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13290260.html
Copyright © 2011-2022 走看看