Advertisement
Dzham

Untitled

Jan 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <vector>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. void fact2(int n) {
  10. unsigned long long int MAXIMUM = 1000000000000;
  11. vector<unsigned long long int> result = { 1 };
  12. for (int i = 2; i <= n; i++) {
  13. unsigned long long int d = 0;
  14. for (int j = 0; j < result.size(); j++) {
  15. unsigned long long int p = result[j] * i + d;
  16. result[j] = p % MAXIMUM;
  17. d = p / MAXIMUM;
  18. /*cout << d << " d" << endl;
  19. cout << result.size() << " size" << endl;*/
  20. }
  21. /*cout << "end?" << endl;*/
  22. if (d > 0) {
  23. /*cout << d << " not end" << endl;*/
  24. result.push_back(d);
  25. }
  26. /*coutVector2(result);
  27. cout << endl;*/
  28. }
  29. ofstream myfile;
  30. myfile.open("output.txt");
  31. myfile << result[result.size() - 1];
  32. for (int i = result.size() - 2; i >= 0; i--) {
  33. myfile << setfill('0') << setw(12) << result[i];
  34. }
  35. myfile.close();
  36. }
  37.  
  38. int main() {
  39. string INT;
  40. ifstream infile;
  41. infile.open("input.txt");
  42. getline(infile, INT);
  43. int n = stoi(INT);
  44. infile.close();
  45. fact2(n);
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement