#include <stdio.h> #include <math.h> unsigned int test(unsigned int k) { unsigned int s = (unsigned int)sqrt(k); unsigned int a,b,r; // a*b+r unsigned int wa,wb,wr=0; if(k==1) { return 1; } else if(k==2) { return 2; } else if(k==3) { return 3; } a=s; r=k%s; b=r?s:k/s; wa=test(a); wb=test(b); if(r>0) { wr=test(r); } return wa+wb+wr; } unsigned int prn(unsigned int k) { unsigned int s = (unsigned int)sqrt(k); unsigned int a,b,r; // a*b+r unsigned int wa,wb,wr=0; if(k==1) { printf("1"); return 1; } else if(k==2) { printf("(1+1)"); return 2; } else if(k==3) { printf("(1+1+1)"); return 3; } a=s; r=k%s; b=r?s:k/s; printf("("); wa=prn(a); printf("*"); wb=prn(b); if(r>0) { printf("+"); wr=prn(r); } printf(")"); return wa+wb+wr; } int main(void) { unsigned int t,k,i=0,w; scanf("%u",&t); for(;i<t;++i) { scanf("%u",&k); w=test(k); if(w>100) { printf("NIE"); } else { prn(k); } printf("\n"); } 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 | #include <stdio.h> #include <math.h> unsigned int test(unsigned int k) { unsigned int s = (unsigned int)sqrt(k); unsigned int a,b,r; // a*b+r unsigned int wa,wb,wr=0; if(k==1) { return 1; } else if(k==2) { return 2; } else if(k==3) { return 3; } a=s; r=k%s; b=r?s:k/s; wa=test(a); wb=test(b); if(r>0) { wr=test(r); } return wa+wb+wr; } unsigned int prn(unsigned int k) { unsigned int s = (unsigned int)sqrt(k); unsigned int a,b,r; // a*b+r unsigned int wa,wb,wr=0; if(k==1) { printf("1"); return 1; } else if(k==2) { printf("(1+1)"); return 2; } else if(k==3) { printf("(1+1+1)"); return 3; } a=s; r=k%s; b=r?s:k/s; printf("("); wa=prn(a); printf("*"); wb=prn(b); if(r>0) { printf("+"); wr=prn(r); } printf(")"); return wa+wb+wr; } int main(void) { unsigned int t,k,i=0,w; scanf("%u",&t); for(;i<t;++i) { scanf("%u",&k); w=test(k); if(w>100) { printf("NIE"); } else { prn(k); } printf("\n"); } return 0; } |