#include <iostream> using namespace std; const int MAX=3000;//试出来的 struct bigInterger { int data[MAX]; int length = 1; bigInterger(); bigInterger(int l); bigInterger operator*(bigInterger b); bigInterger operator+(bigInterger b); void calculateLength(); }; bigInterger::bigInterger() { for (int i = 0; i < MAX; i++) { data[i] = 0; } } bigInterger::bigInterger(int l) { for (int i = 0; i < MAX; i++) { data[i] = 0; } if (l == 0) return; int i = 0; while (l != 0) { data[i++] = l % 10; l /= 10; } length = i; } void bigInterger::calculateLength() { int count = 0; int i = 99; while (data[i--] != 0) { count++; } length = MAX - count; } bigInterger bigInterger::operator*(bigInterger b) { bigInterger ans = bigInterger(); ans.length=length + b.length;//乘积的位数最多是乘数位数的和 for (int i = 0; i < b.length; i++) { for (int j = 0; j < length; j++) { ans.data[i + j] += b.data[i] * data[j]; } } int carry = 0; for (int i = 0; i < ans.length; i++) { int temp = ans.data[i] + carry; ans.data[i] = temp % 10; carry = temp / 10; } for(int i=ans.length-1;i>=0;i--){//计算位数时不算前导零 if(ans.data[i]==0) ans.length--; else break; } return ans; } int main() { int n; while (cin >> n) { // 注意 while 处理多个 case // cout << a + b << endl; if (n == 0) { cout << 1 << endl; continue; } bigInterger ans = bigInterger(1); while (n != 1) { ans = ans * bigInterger(n--); } for (int i = ans.length - 1; i >= 0; i--) { cout << ans.data[i]; } cout << endl; } } // 64 位输出请用 printf("%lld")