fork(1) download
  1. #include <iostream>
  2.  
  3. #define COEF 10000000
  4. #define TEN 10
  5.  
  6. using namespace std;
  7.  
  8. unsigned int arr[] = { 1, 94194688,80754176,28792576,93638144,44194688,16269824,94550272,61946112,68933632,
  9. 68754176,19323648,22612992,36351232,57997312,66792576,2167808,95748096,88043776,
  10. 37690112,65638144,99247872,80831232,42968832,38960896,2194688,36401664,29433088,
  11. 21091328,35679232,40269824,3200512,39416576,62174976,23727104,49750272,52626176,
  12. 72337664,68916224,93513984,25146112,14722816,60257024,2170112,13989632,28933632,
  13. 91983872,29619968,23259904,52859904,2354176,61171456,14485248,81225984,93129472,
  14. 98123648,42294528,83940096,91339008,90945024,77812992,83786752,30308352,33122816,
  15. 709376,45551232,13495552,4053504,28486912,65094912,93197312,79194112,80894208,
  16. 48729344,89670656,26832576,59147776,51826688,14217984,72698112,10487808,29000448,
  17. 21455616,72560128,94383616,23588096,83462144,14917632,85698816,11810304,3083776,
  18. 84299264,11034368,6525952,27101696,68170112,92235008,45980416,15386112,44244224,
  19. 3398144 };
  20.  
  21. int main()
  22. {
  23. int N;
  24. unsigned long long factorial = 1;
  25. cin >> N;
  26.  
  27. int idx = N/COEF;
  28. factorial = arr[idx];
  29.  
  30. int start = !N%COEF ? idx*COEF : idx*COEF + 1;
  31.  
  32. if (N % COEF != 0)
  33. {
  34. for(int i = start; i <= N; i++)
  35. {
  36. factorial *= i;
  37.  
  38. while(factorial % TEN == 0) factorial /= TEN;
  39. factorial %= COEF;
  40. }
  41. }
  42.  
  43. factorial %= TEN*TEN*TEN;
  44. cout << factorial/(TEN*TEN) << (factorial/TEN)%TEN << factorial%TEN;
  45. return 0;
  46.  
  47. }
Success #stdin #stdout 0s 4880KB
stdin
17
stdout
096