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;
    }
  • 相关阅读:
    将python对象序列化成php能读取的格式(即能反序列化到对象)
    Atitit.研发管理---api版本号策略与版本控制
    Atitit.研发管理---api版本号策略与版本控制
    Atitit.jsou html转换纯文本 java c# php
    Atitit.jsou html转换纯文本 java c# php
    atitit.基于bat cli的插件管理系统.doc
    atitit.基于bat cli的插件管理系统.doc
    atititi.soa  微服务 区别 联系 优缺点.doc
    atititi.soa  微服务 区别 联系 优缺点.doc
    userService 用户 会员 系统设计 v2 q224 .doc
  • 原文地址:https://www.cnblogs.com/dealer/p/12990051.html
Copyright © 2011-2022 走看看