Advertisement
Guest User

Untitled

a guest
May 6th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <vector>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <map>
  11. #include <set>
  12. #include <stdlib.h>
  13. #include <sstream>
  14. #include <assert.h>
  15.  
  16. #include <time.h>
  17. #pragma comment(linker, "/STACK:20000000")
  18.  
  19. #define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
  20. #define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
  21. #define mp make_pair
  22. #define pb push_back
  23. #define ll long long
  24.  
  25. using namespace std;
  26.  
  27. int ri(){int x;scanf("%d",&x);return x;}
  28. ll rll(){ll x;scanf("%lld",&x);return x;}
  29.  
  30. void solve()
  31. {
  32.     ll n;
  33.     cin >> n;
  34.    
  35.     const ll MAXN=1e7;
  36.     assert(n<=MAXN);
  37.    
  38.     ll res=1;
  39.     ll x=5;
  40.     ll cnt=0;
  41.     while(x<=n)
  42.         cnt+=n/x,x*=5LL;
  43.     fr(i,2,n)
  44.     {
  45.         x=i;
  46.         while(x%5==0)
  47.             x/=5;
  48.         while(cnt && x%2==0)
  49.             x/=2,cnt--;
  50.         x%=1000;
  51.         res*=x;
  52.         res%=1000;
  53.     }
  54.     res%=1000;
  55.     if (n>=8)
  56.     {
  57.         if (res<10)
  58.             cout << "00";
  59.         else
  60.         if (res<100)
  61.             cout << "0";
  62.     }
  63.     cout << res << endl;
  64. }
  65.  
  66. int main()
  67. {
  68.     /*#ifndef ONLINE_JUDGE
  69.         freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
  70.         freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
  71.     #else
  72.         //freopen("input.in","rt",stdin);
  73.         //freopen("output.out","wt",stdout);
  74.     #endif*/
  75.  
  76.     solve();
  77.  
  78.     /*#ifndef ONLINE_JUDGE
  79.         printf("\n\ntime-%.3lf",clock()*1e-3);
  80.     #endif*/
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement