Cod sursa(job #2062315)

Utilizator Andrei_RAndrei Roceanu Andrei_R Data 10 noiembrie 2017 11:03:37
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int main()
{
    int p,n,x,nr,d,i;
    fin>>p;
    if(p==0){fout<<1;return 0;}
    nr=0;i=1;n=-1;
    for(n=p*4;nr!=p;n+=i)
    {
        nr=0;x=n;d=5;
        while(d<=n)
        {
            nr+=n/d;
            d*=5;
        }
        if(!(n%5))i=5;
        if(nr>p){fout<<-1;return 0;}
    }
    fout<<n-i;
}