Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2023 /round1 /sum_41_ch1.cpp
wjomlex's picture
2023 Problems
ff444f7 verified
raw
history blame contribute delete
721 Bytes
#include <iostream>
#include <vector>
using namespace std;
void solve() {
int P;
cin >> P;
int curr_sum = 0;
vector<int> factors;
for (int i = 2; i*i <= P; ) {
if (P % i == 0) {
factors.push_back(i);
curr_sum += i;
P /= i;
} else {
i++;
}
}
if (P > 1) {
curr_sum += P;
factors.push_back(P);
}
if (curr_sum > 41) {
cout << " -1";
return;
}
while (curr_sum < 41) {
factors.push_back(1);
curr_sum++;
}
cout << " " << factors.size();
for (int f : factors) {
cout << " " << f;
}
}
int main() {
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
cout << "Case #" << t << ":";
solve();
cout << endl;
}
return 0;
}