zoukankan      html  css  js  c++  java
  • C. Fadi and LCM

    Today, Osama gave Fadi an integer XX, and Fadi was wondering about the minimum possible value of max(a,b)max(a,b) such that LCM(a,b)LCM(a,b) equals XX. Both aa and bb should be positive integers.

    LCM(a,b)LCM(a,b) is the smallest positive integer that is divisible by both aa and bb. For example, LCM(6,8)=24LCM(6,8)=24, LCM(4,12)=12LCM(4,12)=12, LCM(2,3)=6LCM(2,3)=6.

    Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?

    Input

    The first and only line contains an integer XX (1X10121≤X≤1012).

    Output

    Print two positive integers, aa and bb, such that the value of max(a,b)max(a,b) is minimum possible and LCM(a,b)LCM(a,b) equals XX. If there are several possible such pairs, you can print any.

    Examples
    input
    Copy
    2
    
    output
    Copy
    1 2
    
    input
    Copy
    6
    
    output
    Copy
    2 3
    
    input
    Copy
    4
    
    output
    Copy
    1 4
    
    input
    Copy
    1
    
    output
    Copy
    1 1
    

     刚开始想多了,直接模拟不就完了。。。

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define pb              push_back
    #define mk              make_pair
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const int mod = 998244353;
    const int N = 2e5 + 5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    ll lcm(ll m, ll n)
    {
        return m * n / gcd(m, n);
    }
    
    int main()
    {
        ll x;
        cin >> x;
        for (ll i = sqrt(x); i >= 1; i--)
        {
            if (x % i==0 && lcm(i,x/i)==x)
            {
                cout << i <<" "<< x / i << endl;
                break;
            }
        }
        return 0;
    }
  • 相关阅读:
    定制化培养:破解企业人才之困
    IT毕业生需要具备的六种能力素质
    JAVA值传递or引用传递
    就业形势严峻 毕业生需练好“内功”
    如何改变mysql auto increment 步长和初始值
    python变量作用域
    关于python的lxml.html 的fromstring 函数
    python string 到date object
    python mysql 连接数据库 latin1 codec错误
    python 使用 mysqldb 批量插入数据
  • 原文地址:https://www.cnblogs.com/dealer/p/12990051.html
Copyright © 2011-2022 走看看