#include <iostream>
//#include <vector>
using namespace std;
const int N = 1000 * 1000 + 5;
//string zapisy[N];
//vector<int> zapisaneLiczby;
string stworzZapis(int liczba)
{
if(liczba == 1)
return "1";
else if(liczba == 2)
return "1+1";
else if(liczba == 3)
return "1+1+1";
else if(liczba % 2 == 0)
return "(1+1)*(" + stworzZapis(liczba / 2) + ")";
else
return "1+(" + stworzZapis(liczba - 1) + ")";
}
int main()
{
short testy;
cin >> testy;
for(int l = 0; l < testy; l++)
{
int liczba;
cin >> liczba;
cout << stworzZapis(liczba) << '\n';
}
}
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 | #include <iostream> //#include <vector> using namespace std; const int N = 1000 * 1000 + 5; //string zapisy[N]; //vector<int> zapisaneLiczby; string stworzZapis(int liczba) { if(liczba == 1) return "1"; else if(liczba == 2) return "1+1"; else if(liczba == 3) return "1+1+1"; else if(liczba % 2 == 0) return "(1+1)*(" + stworzZapis(liczba / 2) + ")"; else return "1+(" + stworzZapis(liczba - 1) + ")"; } int main() { short testy; cin >> testy; for(int l = 0; l < testy; l++) { int liczba; cin >> liczba; cout << stworzZapis(liczba) << '\n'; } } |
English