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;
    }
  • 相关阅读:
    OpenStack 中的neutron-server启动过程
    NYOJ 284 坦克大战 【BFS】+【优先队列】
    HDSF主要节点解说(二)工作原理
    SQL SERVER中的流程控制语句
    Android 自己定义View (二) 进阶
    JNI学习积累之一 ---- 常用函数大全
    Android NDK开发之Jni的数据类型
    CMakeListx.txt 编辑语法学习
    用CMake代替makefile进行跨平台交叉编译
    Android 开发--CMakeList调用本地so文件
  • 原文地址:https://www.cnblogs.com/dealer/p/12990051.html
Copyright © 2011-2022 走看看