#include <iostream>
#include <vector>
using namespace std;
const int FACTORS = 100;
void set(vector<bool> v, int m)
{
int s = v.size();
for (int i = m+m; i < s; i++)
v[i] = true;
}
int main()
{
ios_base::sync_with_stdio(false);
vector<bool> v(FACTORS,false);
v[0] = true;
v[1] = true;
for (int i = 2; i < FACTORS; i++)
{
if (!v[i]) set(v,i);
}
vector<int> factors;
factors.reserve(FACTORS);
for (int i = 0; i < FACTORS; i++)
if (!v[i]) factors.push_back(i);
int t;
cin >> t;
for (int i = 0; i < t; i++)
{
int k;
cin >> k;
vector<int> fk;
fk.reserve(30);
int val = k;
int fs = factors.size();
int sum = 0;
for (int j = 0; j < fs && val > 1; j++)
{
while ((val % factors[j]) == 0)
{
fk.push_back(factors[j]);
val = val / factors[j];
sum += factors[j];
}
}
if (val > 1 || sum > 100) cout << "NIE";
else {
auto printnum = [](int v) { cout << "1"; while (v-->1) cout << "+1"; };
if (fk.empty()) cout << "1";
else if (fk.size() == 1) printnum(fk[0]);
else
{
auto it = fk.begin();
auto printnump = [&printnum](int v) { cout << "("; printnum(v); cout << ")"; };
printnump(*it);
while ((++it) != fk.end())
{
cout << "*";
printnump(*it);
}
}
}
cout << endl;
}
return 0;
}
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #include <iostream> #include <vector> using namespace std; const int FACTORS = 100; void set(vector<bool> v, int m) { int s = v.size(); for (int i = m+m; i < s; i++) v[i] = true; } int main() { ios_base::sync_with_stdio(false); vector<bool> v(FACTORS,false); v[0] = true; v[1] = true; for (int i = 2; i < FACTORS; i++) { if (!v[i]) set(v,i); } vector<int> factors; factors.reserve(FACTORS); for (int i = 0; i < FACTORS; i++) if (!v[i]) factors.push_back(i); int t; cin >> t; for (int i = 0; i < t; i++) { int k; cin >> k; vector<int> fk; fk.reserve(30); int val = k; int fs = factors.size(); int sum = 0; for (int j = 0; j < fs && val > 1; j++) { while ((val % factors[j]) == 0) { fk.push_back(factors[j]); val = val / factors[j]; sum += factors[j]; } } if (val > 1 || sum > 100) cout << "NIE"; else { auto printnum = [](int v) { cout << "1"; while (v-->1) cout << "+1"; }; if (fk.empty()) cout << "1"; else if (fk.size() == 1) printnum(fk[0]); else { auto it = fk.begin(); auto printnump = [&printnum](int v) { cout << "("; printnum(v); cout << ")"; }; printnump(*it); while ((++it) != fk.end()) { cout << "*"; printnump(*it); } } } cout << endl; } return 0; } |
English