UVa 10220 I Love Big Numbers ! (简单高精度)
2013-11-21 20:38
1051 查看
10220 - I Love Big Numbers !
Time limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1161
The Problem
A Japanese young girl went to a Science Fair at Tokyo. There she met with a Robot named Mico-12, which had AI (You must know about AI-Artificial Intelligence). The Japanese girl thought, she can do some fun with that Robot. She asked her,"Do you have any idea about maths ?"."Yes! I love mathematics", The Robot replied.
"Okey ! Then I am giving you a number, you have to find out the Factorial of that number. Then find the sum of the digits of your result!. Suppose the number is 5.You first calculate 5!=120, then find sum of the digits 1+2+0=3.Can you do
it?"
"Yes. I can do!"Robot replied.
"Suppose the number is 100, what will 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 you tell that ?" Robot asked the girl. "Because I am an ACM World Finalist and I can solve the Big Number problems easily." Saying this, the girl closed her laptop computer and went away.
Now, your task is to help the Robot with the similar problem.
The Input
The input file will contain one or more test cases.Each test case consists of one line containing an integers n (n<=1000).
The Output
For each test case, print one line containing the required number. This number will always fit into an integer, i.e. it will be less than 2^31-1.Sample Input
5 60 100
Sample Output
3 288 648
完整代码:
/*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 % 10; } local += 3; } sum = 0; for (i = 0; i < 3000; ++i) sum += num[i]; printf("%d\n", sum); } return 0; }
相关文章推荐
- UVa10220 - I Love Big Numbers !
- UVa 10220 - I Love Big Numbers !
- UVA 763 - Fibinary Numbers(高精度斐波那契)
- UVA 763 - Fibinary Numbers(高精度斐波那契 + 高精度模板)
- UVa 10013 Super long sums (简单高精度)
- UVA 10106 Product 简单高精度乘法
- UVa10464 - Big Big Real Numbers
- I Love Big Numbers!
- uva 10284 - Arif in Dhaka(First Love Part)等价类计数(Polya定理)
- uva - 11636 - Hello World!(简单数学)
- Where is the Marble? Uva_10474 ——最为简单的排序和检索
- uva 748 Exponentiation 浮点数乘方运算 高精度水题
- 简单几何(相对运动距离最值) UVA 11796 Dog Distance
- UVa 10012 How Big Is It? (枚举&细节)
- UVALive 7270 Osu! Master(简单水题)
- 递推+高精度 UVA 10497 Sweet Child Makes Trouble(可爱的孩子惹麻烦)
- UVA 465 Overflow 高精度加法乘法(误!。其实应该说是浮点数的优势。。。)
- UVa 424 Integer Inquiry (高精度)
- UVa 10494 If We Were a Child Again (高精度)
- uva 10539——Almost Prime Numbers