Last active
November 5, 2019 08:55
-
-
Save pinglunliao/455bff925d54881beb73 to your computer and use it in GitHub Desktop.
c119: 10220 - I Love Big Numbers. FYI: https://yunlinsong.blogspot.com/2015/03/c119-10220-i-love-big-numbers.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// val 存結果。p 紀錄階乘結果。psize 紀錄算到多少階乘。 | |
int val[1001], p[10000], psize = 0; | |
int main(){ | |
int i, j, n; | |
p[0] = 1; | |
val[0] = 1; | |
for(i = 1; i <= 1000; i++){ | |
for(j = 0; j <= psize; j++){ | |
p[j] *= i; | |
} | |
// 進位處理 | |
for(j = 0; j <= psize; j++){ | |
p[j+1] += p[j]/10; | |
p[j] %= 10; | |
val[i] += p[j]; | |
} | |
while(p[psize+1]){ | |
psize++; | |
p[psize+1] += p[psize]/10; | |
p[psize] %= 10; | |
val[i] += p[psize]; | |
} | |
} | |
while(scanf("%d", &n)==1){ | |
printf("%d\n", val[n]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment