Advertisement
Utkar5hM

Untitled

Feb 16th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. void extraLongFactorials(int n) {
  2.  
  3.     vector <int> a;
  4.     a.push_back(1);
  5.     int c(0);
  6.     int d(0);
  7.     for(int i(2);n>=i;++i){
  8.         int m = a.size();
  9.         for(int j(0);j<m;j++){
  10.             int k = a[j]*i + c*d;
  11.             a[j] = k%10;
  12.             c=0;
  13.             if(k>=10){
  14.                 if(j+1==m){
  15.                 a.push_back(k/10);
  16.                 } else {
  17.                 c=1;
  18.                 d=k/10;
  19.                 }
  20.             }
  21.         }
  22.         while(a[a.size()-1]>10){
  23.             int r = a[a.size()-1];
  24.             a[a.size()-1] = r%10;
  25.             a.push_back(r/10);
  26.         }
  27.     }
  28.     for(int i(a.size()-1); i>=0;--i ){
  29.     cout << a[i];
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement