题解 | #N的阶乘#
N的阶乘
https://www.nowcoder.com/practice/f54d8e6de61e4efb8cce3eebfd0e0daa
#include <bits/stdc++.h> using namespace std; vector<int> multiply(vector<int>& a, int num){ int carry = 0; vector<int> res; for(int i=0;i<a.size();i++){ carry = a[i]*num + carry; res.push_back(carry%10); carry /= 10; } while(carry){ res.push_back(carry%10); carry /= 10; } return res; } int main() { int n; while(cin >> n) { vector<int> ans; ans.push_back(1); for(int i=n;i>1;i--){ ans = multiply(ans, i); } for(int i=ans.size()-1;i>=0;i--){ cout<<ans[i]; } cout<<endl; } return 0; }