#include <iostream>
#include <vector>
#include <math.h>
#include <string>
using namespace std;
bool fT = true;
string output="";
int licznik = 0;
int wypiszDlaP(int a) {
if (a == 1) { output += "1"; return 1; }
int k = 2;
while (k<=a) {
while (a%k == 0) {
a /= k;
if (k <= 3) {
if (!fT)output+= "*";
fT = false;
output+= "(1";
if (++licznik > 100)return 0;
for (int i = 1; i < k; i++) {
output+= "+1";
if (++licznik > 100)return 0;
}
output+= ")";
}
else {
if (!fT)output+= "*";
output+= "(";
fT = true;
wypiszDlaP(k-1);
output+= "+1)";
if (++licznik > 100)return 0;
}
}
k++;
}
return 1;
}
int main(int argc, char** argv) {
int i;
cin >> i;
for (; i > 0; i--) {
int a;
cin >> a;
output = "";
fT = true;
licznik = 0;
if (wypiszDlaP(a) == 0) {
cout << "NIE"<<endl;
}
else {
cout << output << 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 | #include <iostream> #include <vector> #include <math.h> #include <string> using namespace std; bool fT = true; string output=""; int licznik = 0; int wypiszDlaP(int a) { if (a == 1) { output += "1"; return 1; } int k = 2; while (k<=a) { while (a%k == 0) { a /= k; if (k <= 3) { if (!fT)output+= "*"; fT = false; output+= "(1"; if (++licznik > 100)return 0; for (int i = 1; i < k; i++) { output+= "+1"; if (++licznik > 100)return 0; } output+= ")"; } else { if (!fT)output+= "*"; output+= "("; fT = true; wypiszDlaP(k-1); output+= "+1)"; if (++licznik > 100)return 0; } } k++; } return 1; } int main(int argc, char** argv) { int i; cin >> i; for (; i > 0; i--) { int a; cin >> a; output = ""; fT = true; licznik = 0; if (wypiszDlaP(a) == 0) { cout << "NIE"<<endl; } else { cout << output << endl; } } return 0; } |
English