// Example program
#include <iostream>
#include <string>
#include <cstdint>
#include <cstring>
#include <math.h>
using namespace std;
int gpow(int x){
int g = 0;
float div_ = x;
do{
div_ = div_/2;
g++;
}while(div_ >= 1);
return g-1;
}
string addpow(int x){
string a;
for(int h = 0;h<x;h++){
if(h+1<x){
a += "(1+1)*";
}
else{
a += "(1+1)";
}
}
return a;
}
int main()
{
int t = 0;
int number = 0;
int tpow = 0;
int rest = 0;
int iz = 0;
string eq;
cin>>t;
for(int i =0;i<t;i++){
cin>>number;
if(number<100){
for(int j = 0;j<number;j++){
cout<<"1";
if((j+1)<number){
cout<<"+";
}
else{
cout<<endl;
}
}
}
else if(number<1000000000){
tpow = gpow(number);
rest = number-pow(2,tpow);
eq = addpow(tpow);
iz += tpow;
eq += "+";
do{
tpow = gpow(rest);
if(tpow > 0){
rest = rest-pow(2,tpow);
eq += addpow(tpow);
iz += tpow*2;
if(rest != 0){
eq += "+";
}
}
}while(tpow>0);
if(rest != 0){
for(int h =0;h<rest;h++){
if(h+1<rest){
eq += "1+";
}
else{
eq += "1";
}
iz += 1;
}
}
cout<<eq<<endl;
// cout<<iz<<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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | // Example program #include <iostream> #include <string> #include <cstdint> #include <cstring> #include <math.h> using namespace std; int gpow(int x){ int g = 0; float div_ = x; do{ div_ = div_/2; g++; }while(div_ >= 1); return g-1; } string addpow(int x){ string a; for(int h = 0;h<x;h++){ if(h+1<x){ a += "(1+1)*"; } else{ a += "(1+1)"; } } return a; } int main() { int t = 0; int number = 0; int tpow = 0; int rest = 0; int iz = 0; string eq; cin>>t; for(int i =0;i<t;i++){ cin>>number; if(number<100){ for(int j = 0;j<number;j++){ cout<<"1"; if((j+1)<number){ cout<<"+"; } else{ cout<<endl; } } } else if(number<1000000000){ tpow = gpow(number); rest = number-pow(2,tpow); eq = addpow(tpow); iz += tpow; eq += "+"; do{ tpow = gpow(rest); if(tpow > 0){ rest = rest-pow(2,tpow); eq += addpow(tpow); iz += tpow*2; if(rest != 0){ eq += "+"; } } }while(tpow>0); if(rest != 0){ for(int h =0;h<rest;h++){ if(h+1<rest){ eq += "1+"; } else{ eq += "1"; } iz += 1; } } cout<<eq<<endl; // cout<<iz<<endl; } } return 0; } |
English