-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFadiLcm.cpp
More file actions
executable file
·54 lines (45 loc) · 1.41 KB
/
FadiLcm.cpp
File metadata and controls
executable file
·54 lines (45 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// g++ FadiLcm.cpp -o FadiLcm && ./FadiLcm
/*
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL)
#define endl '\n'
#define ll long long int
using namespace std;
#define pii pair <ll , ll >
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
bool fun(pair<ll, ll> a, pair<ll, ll> b){
return max(a.first, a.second) < max(b.first, b.second);
}
int main(){
ll n;
cin >> n;
ll cn = n;
vector<ll> factors;
ll root_n = sqrt(n);
for (ll i = 2; i < root_n; i++){
while (n % i == 0) {
factors.push_back(i);
n /= i;
}
}
int size = factors.end() - factors.begin();
if(size){
vector<pair<ll, ll>> multiple(size);
multiple[0].first = factors[0];
multiple[0].second = cn/factors[0];
// for(auto i : factors) cout << i << " "; cout << endl;
for(int i = 1; i < size; i++){
multiple[i].first = multiple[i-1].first*factors[i];
multiple[i].second = cn/multiple[i].first;
}
sort(multiple.begin(), multiple.end(), fun);
cout << multiple[0].first << " " << multiple[0].second << endl;
}
else {
cout << 1 << " " << cn << endl;
}
return 0;
}