Files
contests/2022/republic/d0/problem05/problem05.cpp
2022-06-01 20:14:50 +03:00

52 lines
853 B
C++

#include <iostream>
#include <set>
#include <cmath>
using namespace std;
int main() {
int64_t N;
cin >> N;
set<int64_t> factors;
int64_t stop = sqrt(N);
int factorsFound = 0;
for (int64_t i = 2; i <= stop; i++) {
if (N % i == 0) {
factors.insert(i);
factors.insert(N / i);
factorsFound++; // Does not represent the size of the set, but the amount of highest factors
if (factorsFound >= 6) {
break;
}
}
}
int64_t power = 0;
string result = "DBVJKM";
int charactersUsed = 0;
auto it = factors.rbegin();
auto end = factors.rend();
while (power < N && charactersUsed < 6) {
if (it != end) {
power += *it;
it++;
} else {
power += 1;
}
charactersUsed++;
}
if (power < N) {
cout << "NO" << endl;
} else {
result = result.substr(0, charactersUsed);
cout << result << endl;
}
return 0;
}