#include <bits/stdc++.h> using namespace std; long long n ,a,w,a1,j,l; int main () { cin >> n; for (int i=0;i<n;i++) { cin >> a; if (a%2==0&&a!=2) { cout << "(1+1)"; a=a/2; l=2; } else if (a%3==0&&a!=3) { cout << "(1+1+1)"; a=a/3; l=3; } else if (a%5==0&&a!=5) { cout << "(1+1+1+1+1)"; a=a/5; l=5; } else if (a%7==0&&a!=7) { cout << "(1+1+1+1+1+1+1)"; a=a/7; l=7; } else if (a==2) { cout << "1+1" << endl; a=1; } else if (a==3) { cout << "1+1+1" << endl; a=1; } else if (a==5) { cout << "1+1+1+1+1"<<endl; a=1; } else if (a==7) { cout << "1+1+1+1+1+1+1" << endl; a=1; } else if (a==1) { cout << "1" << endl; } else { cout << "1"; a--; } while (a!=1) { if (a%2==0) { cout << "*(1+1)"; a=a/2; l=2; } else if (a%3==0) { cout << "*(1+1+1)"; a=a/3; l=3; } else if (a%5==0) { cout << "*(1+1+1+1+1)"; a=a/5; l=5; } else if (a%7==0) { cout << "*(1+1+1+1+1+1+1)"; a=a/7; l=7; } else { j+=1*l; a--; } if (a==1) { for (int l=0;l<j;l++) { cout << "+1"; } j=0; cout << endl; } } } }
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 | #include <bits/stdc++.h> using namespace std; long long n ,a,w,a1,j,l; int main () { cin >> n; for (int i=0;i<n;i++) { cin >> a; if (a%2==0&&a!=2) { cout << "(1+1)"; a=a/2; l=2; } else if (a%3==0&&a!=3) { cout << "(1+1+1)"; a=a/3; l=3; } else if (a%5==0&&a!=5) { cout << "(1+1+1+1+1)"; a=a/5; l=5; } else if (a%7==0&&a!=7) { cout << "(1+1+1+1+1+1+1)"; a=a/7; l=7; } else if (a==2) { cout << "1+1" << endl; a=1; } else if (a==3) { cout << "1+1+1" << endl; a=1; } else if (a==5) { cout << "1+1+1+1+1"<<endl; a=1; } else if (a==7) { cout << "1+1+1+1+1+1+1" << endl; a=1; } else if (a==1) { cout << "1" << endl; } else { cout << "1"; a--; } while (a!=1) { if (a%2==0) { cout << "*(1+1)"; a=a/2; l=2; } else if (a%3==0) { cout << "*(1+1+1)"; a=a/3; l=3; } else if (a%5==0) { cout << "*(1+1+1+1+1)"; a=a/5; l=5; } else if (a%7==0) { cout << "*(1+1+1+1+1+1+1)"; a=a/7; l=7; } else { j+=1*l; a--; } if (a==1) { for (int l=0;l<j;l++) { cout << "+1"; } j=0; cout << endl; } } } } |