Cod sursa(job #1751255)

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

using namespace std;

ifstream q("factorial.in");
wfstream w("factorial.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;}
//    for(n=5;s<p;n+=5)
//    {
//        int x=n;
//        while(x)
//        {
//            if(x%5==0) s++;
//            x/=5;
//        }
//    }
    n=5;
    while(s<p)
    {
        s+=pow5(n);
        n+=5;
    }
    if(s==p) w<<n-5;
    else w<<"-1";

    return 0;
}