Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. const int MODULE = 1e6;
  6.  
  7. struct longNum {
  8.     vector<ll> en;
  9.     longNum(int a){
  10.         while(a != 0){
  11.             en.push_back(a % MODULE);
  12.             a/=MODULE;
  13.         }
  14.         en.push_back(0);
  15.         //  cout << en.size()<<" partition\n"; //debug
  16.     }
  17.     void mul (int a){
  18.         int c = 0;
  19.         for(int i = 0; i < en.size(); i++){
  20.             int f = ((ll)en[i] * a + c)% MODULE;
  21.                 //  cout << en[i] << " current\n"; //debug
  22.            
  23.             c = (en[i] * a) / MODULE;
  24.             en[i] = f;
  25.             //  cout << c << " mod\n"; //debug
  26.         }
  27.     }
  28.     void Write6(ll x) {
  29.         long long M = 1e5;
  30.         while(M > 0) {
  31.             cout << x/M;
  32.             x%=M;
  33.             M/=10;
  34.         }
  35.     }
  36.     void out(){
  37.         if(en[en.size() - 1] != 0){
  38.             cout << en[en.size() - 1];
  39.         for(int i = en.size() - 2; i >= 0; i--){
  40.             Write6(en[i]);
  41.         }
  42.         }
  43.         else{
  44.             cout << en[en.size() - 2];
  45.             for(int i = en.size() - 3; i >= 0; i--){
  46.             Write6(en[i]);
  47.         }
  48.         }
  49.        
  50.     }
  51. };
  52.  
  53. int main(int argc,char* argv[]) {
  54.  
  55. ios_base::sync_with_stdio(false);
  56. cin.tie(NULL);
  57. /// ya staralsa ;)
  58. int a;
  59. cin >> a;
  60. longNum num (a);
  61. for(int i = 2; i < a; i++){
  62.     num.mul(i);
  63. }
  64.  
  65.  
  66. num.out();
  67.  
  68. ///
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement