#include <bits/stdc++.h>
using namespace std;
const int MAKS = 1e5+2;
vector <int> Primes;
bool Sito [MAKS];
void GenPrime ()
{
Sito[0] = true;
Sito[1] = true;
for (int i = 0; i < MAKS; i++)
{
if (!Sito[i])
{
Primes.push_back(i);
for (int j = i+i; j < MAKS; j += i)
{
Sito[j] = true;
}
}
}
};
int main()
{
//ios_base::sync_with_stdio(0);
int t, n, suma, it, a;
vector < pair<int, int> > V;
GenPrime();
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
suma = 0;
it = Primes.size()-1;
while ((it--) && (n > 1))
{
a = 0;
while (n % Primes[it] == 0)
{
a++;
n /= Primes[it];
}
suma += a;
if (suma > 100)
break;
if (a)
V.push_back(make_pair(Primes[it], a));
}
if (suma > 100)
{
printf("NIE\n");
}
else if (V.empty())
printf("1\n");
else
{
for (int i = 0; i < V.size(); i++)
{
for (int k = 0; k < V[i].second; k++)
{
if ((V.size() > 1) || (V[i].second > 1))
{
printf("(");
}
for (int j = 0; j < V[i].first-1; j++)
{
printf("1+");
}
printf("1");
if ((V.size() > 1) || (V[i].second > 1))
{
printf(")");
}
if (k < V[i].second-1)
printf("*");
}
if (i != V.size()-1)
printf("*");
}
printf("\n");
}
V.clear();
}
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 79 80 81 82 83 84 85 86 87 | #include <bits/stdc++.h> using namespace std; const int MAKS = 1e5+2; vector <int> Primes; bool Sito [MAKS]; void GenPrime () { Sito[0] = true; Sito[1] = true; for (int i = 0; i < MAKS; i++) { if (!Sito[i]) { Primes.push_back(i); for (int j = i+i; j < MAKS; j += i) { Sito[j] = true; } } } }; int main() { //ios_base::sync_with_stdio(0); int t, n, suma, it, a; vector < pair<int, int> > V; GenPrime(); scanf("%d", &t); while (t--) { scanf("%d", &n); suma = 0; it = Primes.size()-1; while ((it--) && (n > 1)) { a = 0; while (n % Primes[it] == 0) { a++; n /= Primes[it]; } suma += a; if (suma > 100) break; if (a) V.push_back(make_pair(Primes[it], a)); } if (suma > 100) { printf("NIE\n"); } else if (V.empty()) printf("1\n"); else { for (int i = 0; i < V.size(); i++) { for (int k = 0; k < V[i].second; k++) { if ((V.size() > 1) || (V[i].second > 1)) { printf("("); } for (int j = 0; j < V[i].first-1; j++) { printf("1+"); } printf("1"); if ((V.size() > 1) || (V[i].second > 1)) { printf(")"); } if (k < V[i].second-1) printf("*"); } if (i != V.size()-1) printf("*"); } printf("\n"); } V.clear(); } return 0; } |
English