fork download
  1.  
  2. #include<bits/stdc++.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. long int noz(long int a);
  7. long int power(long int a,int i);
  8. int main ()
  9. {
  10. int test;
  11. cin >> test;
  12. for (int i = 0; i < test; i++)
  13. {
  14. long int n;
  15. cin >> n;
  16. cout << noz(n) << endl;
  17. }
  18.  
  19. return 0;
  20. }
  21.  
  22. long int noz(long int a)
  23. {
  24. long int counteroftwo = 0;
  25. long int counteroffive = 0;
  26. for (long int i = 2; i <= a; i++)
  27. {
  28. counteroftwo += power(i,2);
  29. counteroffive += power(i,5);
  30. }
  31. if (counteroffive < counteroftwo) return counteroffive;
  32. else return counteroftwo;
  33. }
  34.  
  35. long int power(long int a,int i)
  36. {
  37. long counter = 0;
  38. while (a % i == 0)
  39. {
  40. a = a/i;
  41. counter++;
  42. }
  43. return counter;
  44. }
Success #stdin #stdout 2.72s 4536KB
stdin
1
1000000000
stdout
249999998