Amonin

Untitled

Jan 2nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <cmath>
  6. #include <algorithm>
  7. using namespace std;
  8. int main() {
  9. ifstream fin("input.txt");
  10. int num;
  11. fin >> num;
  12. vector<int> v = { 1 };
  13. vector<int> v_mul = { 0 };
  14. for (int i = 1; i <= num; ++i) {
  15. int size = to_string(i).length() + 1;
  16. for (int j = 0; j < size; ++j) v_mul.push_back(0);
  17. for (int j = 0; j < v.size(); ++j) {
  18. v_mul[j] += v[j] * i;
  19. if (v_mul[j] > 10) {
  20. v_mul[j + 1] += v_mul[j] / 10;
  21. v_mul[j] %= 10;
  22. }
  23. }
  24. int j = v.size();
  25. while (v_mul[j] > 10) {
  26. v_mul[j + 1] += v_mul[j] / 10;
  27. v_mul[j] %= 10;
  28. ++j;
  29. }
  30. while (v_mul[v_mul.size() - 1] == 0) {
  31. v_mul.pop_back();
  32. }
  33. v = v_mul;
  34. v_mul = { 0 };
  35. v_mul.resize(v.size());
  36. }
  37. ofstream cout("output.txt");
  38. reverse(v.begin(), v.end());
  39. for (auto el : v) {
  40. cout << el;
  41. }
  42. cout << endl;
  43. cout.close();
  44. fin.close();
  45. system("pause");
  46. }
Advertisement
Add Comment
Please, Sign In to add comment