What is the nth number of replies of Palindrome Numbers (LA2889 ?, Palindromela2889
J-Palindrome Numbers
Time Limit:3000 MSMemory Limit:0 KB64bit IO Format:% Lld & % llu
Submit Status Practice UVALive 2889WA has a layout, and I am also drunk because of a different compiling environment ...... Tears are everywhere. Link to the question: Please click UVALive 2889 to repost the question. Please specify the Source: search for & STAR kids
1 # include <stdio. h> 2 # define LL long 3 # define MM 2000000000 4 LL num [25] = {0}; 5 LL ppow (LL x, LL y) 6 {7 LL tp = 1; 8 while (y --) 9 {10 tp * = x; 11} 12 return tp; 13} 14 15 void init () 16 {17 LL tp = 9, I; 18 for (I = 1;) 19 {20 num [I] = num [I-1] + tp; 21 I ++; // when there are multiple I in the same industry to process I, do not put I ++ in it, because the variant environment is different; the operation sequence is different, possible wa22 num [I] = num [I-1] + tp; 23 I ++; 24 tp = tp * 10; 25 if (num [I-1]> = MM) break; 26} 27 28/* for (int I = 1; I <21; I ++) 29 {30 LL p = (I + 1)/2-1; 31 num [I] = num [I-1] + 9 * ppow (10, p); 32 // printf ("% lld \ n", num [I]); 33} 34 // printf ("% lld \ n", num [0]); */35} 36 37 int main () 38 {39 init (); 40 LL n; 41 LL a [20]; 42 while (scanf ("% lld", & n), n) 43 {44 int len = 0; 45 for (int I = 1; I <= 20; I ++) 46 {47 if (n <= num [I]) 48 {49 len = I; 50 break; 51} 52} 53 // printf ("len = % d \ n", len); 54 LL m = n-num [len-1]; 55 int l = (len + 1)/2; 56 // printf ("m = % lld \ tl = % d \ n", m, l ); 57 LL ans = ppow (10 L-1) + m-1; 58 // printf ("ans = % lld \ tppow = % lld \ n", ans, ppow (10, l-1); 59 printf ("% lld", ans); 60 if (len & 1) ans/= 10; 61 while (ans) 62 {63 printf ("% lld", ans % 10); 64 ans/= 10; 65} 66 printf ("\ n"); 67} 68 return 0; 69}