1. 程式人生 > >求n(10000以內)的階乘

求n(10000以內)的階乘

#include<iostream>
#include<string>
#include<time.h>
#include<iomanip>
using namespace std;

#include<vector>
void cheng(vector<unsigned long long int> &result, int t)
{
    int temp=0;
    for (auto &x : result)
    {
        unsigned long long int q = (x*t + temp) /1000000000000000
; x = (x*t+temp) % 1000000000000000; temp = q; } if (temp != 0) result.push_back(temp); } int main() { std::ios::sync_with_stdio(false); // int a = clock(); vector<unsigned long long int> result; result.push_back(1); result.clear(); result.push_back(1); int
N;cin >> N; for (int t = 2;t <= N;t++) cheng(result, t); cout << result.back(); for (auto it = result.rbegin() + 1;it != result.rend();it++) cout << setw(15) << setfill('0') << *it; cout << endl; // int b = clock(); // cout << b - a << endl;
}