Cod sursa(job #1929913)

Utilizator RobertAndruscaAndrusca Robert RobertAndrusca Data 18 martie 2017 12:15:29
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <fstream>

using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int main()
{
    long long p, i, j, nr = 0;
    in >> p;
    if(p == 0)out << 1;
    else
    {
       for(i = 5; p > 0; i += 5)
       {
        nr += 5;
        p--;
        j = i / 5;
        while(j % 5 == 0)
        {
          j /= 5;
          p--;
        }
       }
     if(p < 0)nr = -1;
     out << nr;
    }
    return 0;
}