Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- void fact2(int n) {
- unsigned long long int MAXIMUM = 1000000000000;
- vector<unsigned long long int> result = { 1 };
- for (int i = 2; i <= n; i++) {
- unsigned long long int d = 0;
- for (int j = 0; j < result.size(); j++) {
- unsigned long long int p = result[j] * i + d;
- result[j] = p % MAXIMUM;
- d = p / MAXIMUM;
- /*cout << d << " d" << endl;
- cout << result.size() << " size" << endl;*/
- }
- /*cout << "end?" << endl;*/
- if (d > 0) {
- /*cout << d << " not end" << endl;*/
- result.push_back(d);
- }
- /*coutVector2(result);
- cout << endl;*/
- }
- ofstream myfile;
- myfile.open("output.txt");
- myfile << result[result.size() - 1];
- for (int i = result.size() - 2; i >= 0; i--) {
- myfile << setfill('0') << setw(12) << result[i];
- }
- myfile.close();
- }
- int main() {
- string INT;
- ifstream infile;
- infile.open("input.txt");
- getline(infile, INT);
- int n = stoi(INT);
- infile.close();
- fact2(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement