題目地址 http://noi.openjudge.cn/ch0106/14/ 把結果分開存儲,存到數組或容器中
#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;}新聞熱點
疑難解答