Guest User

Untitled

a guest
Jul 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. // Complete the extraLongFactorials function below.
  6. void extraLongFactorials(int n) {
  7. vector<int> d;
  8. d.push_back(1);
  9.  
  10. for (int i = 2; i <= n; ++i) {
  11. for (auto it = d.begin(); it != d.end(); ++it)
  12. *it *= i;
  13.  
  14. for (size_t j = 0; j < d.size(); ++j) {
  15. if (d[j] < 10)
  16. continue;
  17.  
  18. if (j == d.size() - 1)
  19. d.push_back(0);
  20.  
  21. d[j + 1] += d[j] / 10;
  22. d[j] %= 10;
  23. }
  24. }
  25.  
  26. for (auto it = d.rbegin(); it != d.rend(); ++it)
  27. cout << *it;
  28. }
  29.  
  30. int main()
  31. {
  32. int n;
  33. cin >> n;
  34. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  35.  
  36. extraLongFactorials(n);
  37.  
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment