Cod sursa(job #1768887)

Utilizator KropiusRezmerita Mihnea Kropius Data 1 octombrie 2016 16:45:03
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>
#include <limits.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int functie(int n)
{
    int x=5,k=0;
    while(n/x!=0)
    {
        k=k+n/x;
        x=x*5;
    }
    return k;
}
int main()
{   int p;int i=1, j=INT_MAX,ok=0,x,k=0;
    fin>>p;
    if(p==0){fout<<1;
             k=1;}
    else{while(i<=j&&ok==0)
    {
        int m=(i+j)/2;
        if(functie(m)==p) {ok=1;
                            x=m;}
            else if(functie(m)>p) j=m-1;
                    else i=m+1;

    }
    }
    if(ok==1) fout<<(x/5)*5;
         else if(k!=1)fout<<-1;

    return 0;
}