1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <stdio.h> #define ten 10 int arr[1000000] = { 0 }; int cnt = 1; int num[20] = { 0 }; int main() { int n,up=0; scanf("%d", &n); arr[1] = 1; if (n == 1) num[1] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j <= cnt; j++) { arr[j] = (arr[j] * i + up); up = (arr[j] / ten); arr[j] %= ten; if (i == n) { num[arr[j] % ten] += 1; } } while (up != 0) { arr[++cnt] = up % ten; if (i == n) { num[ up % ten ] += 1; } up /= ten; } } printf("%d! --\n", n); for (int i = 0; i < 10; i++) { printf(" (%d) %3d ",i,num[i]); if (i == 4) printf("\n"); } } | cs |
'알고리즘 > 큰 수의 계산' 카테고리의 다른 글
팩토리얼 구하기 더블릿 (0) | 2019.02.28 |
---|---|
2*1, 2*2 타일링 더블릿 (0) | 2019.02.18 |