10220-i Love Big Numbers!
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1161
The Problem
A Japanese young girl went the Fair at Tokyo. There she met with a Robot named Mico-12, which had AI (for you must know about Ai-artificial Intelligence). The Japanese girl thought, she can do some fun and that Robot. She asked her, "Do your have any idea about maths?". yes! I Love Mathematics ", the Robot replied.
"Okey! Then I am giving you a number and you have to find out the factorial of this number. Then find the sum of the digits of your result!. Suppose the number is 5.You a calculate 5!=120, then find sum of the digits 1+2+0=3.can your do it?
"Yes." I can do! " Robot replied.
"Suppose the number is, what would be the result?". At this point the Robot started thinking and calculating. After a few minutes the Robot head burned out and it cried out loudly ' time Limit exceeds '.
The girl laughed at the Robot and said "The sum is definitely 648".
"How can I tell that?" Robot asked the girl. "Because I am a ACM World finalist and I can solve the big number problems easily." Saying this, the girl closed her laptop computer and went away.
Now, the your task are to help the Robot with the similar problem.
The Input
The input file would contain one or more test cases.
Each test case consists of the one line containing a integers n (n<=1000).
The Output
For each test case, print one line containing the required number. This number would always fit into an integer, i.e. it would be less than 2^31-1.
Sample Input
5
60
Sample Output
3
648
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Complete code:
/*0.036s*/
#include <cstdio>
#include <cstring>
int num[3000];
int main ()
{
int i, J, S, C, N, sum, local;
while (~SCANF ("%d", &n))
{
memset (num, 0, sizeof (num));
Num[0] = 1, local = 3;
for (i = 2; I <= n; ++i)
{
c = 0;
for (j = 0; j < local; ++j)
{
s = i * num[j] + C;
c = S/10;
NUM[J] = s%;
}
Local + + 3;
}
sum = 0;
for (i = 0; i < 3000 ++i)
sum + = Num[i];
printf ("%d\n", sum);
}
return 0;
}