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;
    }
  • 相关阅读:
    HTML 嵌入 SWF ,访问域的问题
    Flex 4 中,StageScaleMode 设置
    一句话清除MC下所有的子
    DataGrid 表头标题,表格文字的字体设置
    Flash中,将某个元件置于最顶层
    Android开发中使用SQLite 数据库
    Android多分辨率支持说明
    Android adb shell 命令大全
    Android Camera 使用小结
    Android多分辨率支持以及各种类型图标尺寸大小
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13290260.html
Copyright © 2011-2022 走看看