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;
    }
  • 相关阅读:
    一些qml资料
    qml 的又一个框架
    qml 最新资源
    sql 创建数据库
    sql2008 无法附加数据库
    C#==>匿名方法
    sql alter表字段处理
    哪些字符需要urlencode编码?具体怎么处理?
    vs2010设置编辑器背景颜色
    nbtstat -a <IP> 会显示主机名、所在工作组等信息
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13290260.html
Copyright © 2011-2022 走看看