标签:span ble pre 个数 body style bit names col
对于一个大数来说,一个数的阶乘是非常大的。同样,一个int类型的整数,它的阶乘可能会很大。就拿50来说,它的阶乘位数是65位,就已经远远超出了long long int类型的最大值。这个时候,就要通过字符串的方法来进行阶乘的运算。
1 * 2
2 |
s = 1*2 = 2, array[0] = 2, up = 0
1 * 2 * 3
6 |
s = 2*3 = 6, array[0] = 6, up = 0
1 * 2 * 3 * 4
4 | 2 |
s = 6*4 = 24, array[0] = 4, up = 2, array[1] = 2
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n, i, j; 6 int array[10001] = {0}; 7 array[0] = 1; 8 cin >> n ; 9 10 for( i = 2; i <= n; i++) 11 { 12 int up = 0; 13 for( j = 0; j <= 10000; j++) 14 { 15 int s = array[j]*i+up; 16 array[j] = s%10; 17 up = s/10; 18 } 19 } 20 21 for( j = 10000; j >= 0; j--) 22 if( array[j] != 0) 23 { 24 for( j; j >= 0; j--) 25 cout << array[j]; 26 } 27 return 0; 28 }
标签:span ble pre 个数 body style bit names col
原文地址:https://www.cnblogs.com/yizhaosan/p/10752206.html