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;
    }
  • 相关阅读:
    XNA游戏编程等
    DirectX游戏编程(一):创建一个Direct3D程序
    POJ 1163 The Triangle(简单动态规划)
    web前段canvasjs图表制作一
    ubuntu 使用mysql
    Nginx+ uWSGI +django进行部署
    matplotlib如何绘制直方图、条形图和饼图
    matplotlib animation
    matplotlib 画图中图和次坐标轴
    matplotlib subplot 多图合一
  • 原文地址:https://www.cnblogs.com/dealer/p/12990051.html
Copyright © 2011-2022 走看看