1 while (j < length) 2 { 3 temp = jinwei; 4 jinwei = (a[j] * i + jinwei) / 10; 5 a[j] = (a[j] * i + temp) % 10; 6 j++; 7 }
感觉很巧妙。
1 #include<iostream> 2 3 using namespace std; 4 const int length = 100000; 5 6 int main() 7 { 8 int a[length]; 9 for (int i = 0; i < length; i++) 10 { 11 a[i] = 0; 12 } 13 a[0] = 1; 14 15 int n; 16 cin >> n; 17 for (int i = 2; i <= n; i++) 18 { 19 int jinwei = 0; 20 int j = 0; 21 int temp; 22 23 while (j < length) 24 { 25 temp = jinwei; 26 jinwei = (a[j] * i + jinwei) / 10; 27 a[j] = (a[j] * i + temp) % 10; 28 j++; 29 } 30 } 31 32 int k = length - 1; 33 while (!a[k]) 34 { 35 k--; 36 } 37 while (k >= 0) 38 { 39 cout << a[k]; 40 k--; 41 } 42 43 return 0; 44 }
原文:https://www.cnblogs.com/ZhengLijie/p/12698041.html