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;
    }
  • 相关阅读:
    SDK Tools Dependencies
    hibernate开发中遇到多对多的问题,可以转换为两个一对多
    利用PC 转发 模拟手机端之间socket通信
    假如你被当成精神病关进了精神病院
    通过JSONP实现完美跨域
    查看linux系统版本命令
    Eclipse+python开发环境配置
    linux chkconfig命令参数及用法详解
    Fedora 17 安装后要做的几件事:MP3,桌面定制,root登录等
    Fedora 17 配置 Nginx + Mysql + php
  • 原文地址:https://www.cnblogs.com/dealer/p/12990051.html
Copyright © 2011-2022 走看看