-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto.cpp
More file actions
27 lines (27 loc) · 737 Bytes
/
crypto.cpp
File metadata and controls
27 lines (27 loc) · 737 Bytes
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
// GitHub: EntityPlantt/Kattis
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector <pair <int, int>> factorized;
for (int i = 2; n > 1; i++) {
if (n % i == 0) {
n /= i;
if (factorized.empty() || factorized.back().first != i) {
factorized.push_back(make_pair(i, 0));
}
factorized.back().second++;
i--;
}
}
cout << max_element(factorized.begin(), factorized.end(), [](pair <int, int> a, pair <int, int> b) {
if (a.second == b.second) {
return a.first > b.first;
}
return a.second < b.second;
})->first;
return 0;
}