Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit Status Practice UVALive 2889
題目鏈接:請點擊UVALive 2889
轉載請注明出處:
尋找&星空の孩子
1 #include<stdio.h>
2 #define LL long 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++;//同行有多個i要處理的時候i,不要把i++放裡面,因為變異環境不同;運算順序不同,可能會wa
22 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 }