SGU107 - 987654321 problem

107. 987654321 problem

time limit per test: 0.5 sec. 
memory limit per test: 4096 KB

 

For given number N you must output amount of N-digit numbers, such, that last digits of their square is equal to 987654321.

 

Input

Input contains integer number N (1<=N<=106)

 

Output

Write answer to the output.

 

Sample Input

8

Sample Output

0

题解:用枚举显然超时。只能用观察法了。小于八位的情况数为0,九位有8种情况,当N>9时,九位以上的数字对于后九位都是没有影响的,所以最高位有9种取法,其余大于九位的都是10种取法。然后运用乘法原理得出最终答案。

View Code
 1 #include<stdio.h>
 2 int main(void)
 3 {
 4     int n,i;
 5     scanf("%d",&n);
 6     if(n<=8) printf("0\n");
 7     else
 8     if(n==9) printf("8\n");
 9     else
10     {
11         printf("72");
12         for(i=11;i<=n;i++)
13         printf("0");
14         printf("\n");
15     }
16     return 0;
17 }

 

posted on 2013-03-16 23:33  仗剑奔走天涯  阅读(167)  评论(0编辑  收藏  举报

导航