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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//Michał Maciaszek

#include <bits/stdc++.h>
#include <unistd.h>

using namespace std;

uintmax_t PRIMAL_NUMBERS[25] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
uintmax_t jedynki = 0;
vector <char> out;

void Print(uintmax_t n);

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	uintmax_t t;
	cin >> t;
	
	do
	{
		uintmax_t k;
		uintmax_t dzielnik, sumamod = 0, mod;
		uintmax_t wspolczynnik = 1;
		bool begin = true;
		cin >> k;
		jedynki = 0;
		out.clear();
		if(k <= 100)
		{
			Print(k);
			intmax_t size_ = out.size();
			for(intmax_t i = 0; i < size_; ++i)
				cout << out[i];
			cout << endl;
			continue;
		}
		
		do
		{
			dzielnik = 1;
			mod = 100;
			for(uintmax_t i = 0; i < 25; ++i)
			{
				if(k % PRIMAL_NUMBERS[i] <= mod)
				{
					mod = k % PRIMAL_NUMBERS[i];
					dzielnik = PRIMAL_NUMBERS[i];
				}
			}
			
			if(dzielnik != 1)
			{
				if(!begin)
					out.push_back('*');
				else
					begin = false;
				Print(dzielnik);
				k = (k / dzielnik);
				sumamod += mod * wspolczynnik;
				wspolczynnik *= dzielnik;
			}
			
			if(jedynki > 100)
			{
				break;
			}
			
		}while(k > 1 && dzielnik != 1);
		
		
		
		if(dzielnik == 1)
		{
			Print(k);
		}
		
		if(sumamod != 0)
		{
			out.push_back('+');
			Print(sumamod);
		}
		
		if(jedynki > 100)
		{
			cout << "NIE" << endl;
			continue;
		}
		
		intmax_t size = out.size();
		for(intmax_t i = 0; i < size; ++i)
			cout << out[i];
		
		cout << endl;
		
	}while(--t);
	
	return 0;
}

void Print(uintmax_t n)
{
	if(n == 0)
		return;
		
	if(n == 1)
	{
		out.push_back('1');
		++jedynki;
		return;
	}
	
	out.push_back('('); out.push_back('1');
	++jedynki;
	while(--n)
	{
		out.push_back('+'); out.push_back('1');
		++jedynki;
	}
	
	out.push_back(')');
}