Cod sursa(job #1751259)

Utilizator fulger13Pomirleanu Sebastian fulger13 Data 1 septembrie 2016 00:25:06
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream q("fact.in");
wfstream w("fact.out");

int pow5 (int n)
{
    int put=0, s=5;
    while(1)
    {
        if(n%s==0) {s*=5; put++;}
        else return put;
    }

}

int main()
{int p,s=0;
    long long n;
    q>>p;
    if(p<0) {w<<"-1"; return 0;}
    if(p==0) {w<<"1"; return 0;}

    n=5;
    while(s<p)
    {
        s+=pow5(n);
        n+=5;
    }
    if(s==p) w<<n-5;
    else w<<"-1";

    return 0;
}