#include <iostream> #include <vector> typedef std::vector< long int > VI; typedef VI::iterator ITER; void print( VI v ) { ITER it; /* for( it = v.begin(); it != v.end(); ++it ) { std::cout << *it << " "; } std::cout << std::endl; */ for( it = v.begin(); it != v.end(); ) { std::cout << "("; for( int j = 1; j<(*it); ++j) { std::cout << "1+"; } std::cout << "1)"; if( ++it != v.end() ) std::cout << "*"; } std::cout << std::endl; } void jed( long int k ) { VI v; int curr = 0; int left = k; if ( k <= 100) { v.push_back( k ); print(v); } else { int curr_div = 4; while( (curr < 100) && (left > 3) ) { while( (left%curr_div) == 0 ) { v.push_back( curr_div ); curr += (curr_div ); left /= curr_div; } curr_div++; } if ( (left == 2) || (left == 3 ) ) { v.push_back( left ); curr += left; left = 0; } if( curr <= 100 ) { // std::cout << "UDALO SIE: " << std::endl; print(v); } else { std::cout << "NIE" << std::endl; } } } int main() { VI r; int t; long int d; std::cin >> t; for( int i=0; i<t; ++i ) { std::cin >> d; r.push_back( d ); } for( int i=0; i<t; ++i ) { jed( r[i] ); } 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 | #include <iostream> #include <vector> typedef std::vector< long int > VI; typedef VI::iterator ITER; void print( VI v ) { ITER it; /* for( it = v.begin(); it != v.end(); ++it ) { std::cout << *it << " "; } std::cout << std::endl; */ for( it = v.begin(); it != v.end(); ) { std::cout << "("; for( int j = 1; j<(*it); ++j) { std::cout << "1+"; } std::cout << "1)"; if( ++it != v.end() ) std::cout << "*"; } std::cout << std::endl; } void jed( long int k ) { VI v; int curr = 0; int left = k; if ( k <= 100) { v.push_back( k ); print(v); } else { int curr_div = 4; while( (curr < 100) && (left > 3) ) { while( (left%curr_div) == 0 ) { v.push_back( curr_div ); curr += (curr_div ); left /= curr_div; } curr_div++; } if ( (left == 2) || (left == 3 ) ) { v.push_back( left ); curr += left; left = 0; } if( curr <= 100 ) { // std::cout << "UDALO SIE: " << std::endl; print(v); } else { std::cout << "NIE" << std::endl; } } } int main() { VI r; int t; long int d; std::cin >> t; for( int i=0; i<t; ++i ) { std::cin >> d; r.push_back( d ); } for( int i=0; i<t; ++i ) { jed( r[i] ); } return 0; } |