#include <iostream>
using namespace std;

int SumFactZeros(const int n)
{
    if(n<0) exit(0);
    if(n<5) return 0;
    int counter=0;  
    for(int i=5;i<=n;i++){
       int flag=i;
       while(flag%5==0)
       {
            flag/=5;
         counter++;
       }
    }
    return counter;
}

int SumFactZeros_recursion(const int n)
{
    if(n<0) exit(0);
    if(n<5) return 0;
    int k=n/5;
    return k+SumFactZeros_recursion(k);
}

int main()
{
    for(int n=5;n<=1000;n++)
       if(SumFactZeros(n)==SumFactZeros_recursion(n))
           cout<<n<<"! has "<<SumFactZeros(n)<<" zeros at the end."<<endl;
       else
           cout<<n<<"! has (sorry, difference answers) zeros at the end."<<endl;
   
    system("pause");
    return 0;
}

相关文章: