Cod sursa(job #1507900)

Utilizator c0mradec0mrade c0mrade Data 21 octombrie 2015 23:28:30
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<fstream>
using namespace std;

int nrz(int x)
{
    int sum=0,y=5;
    while(y<=x)
    {
        sum+=x/y;
        y*=5;
    }
    return sum;
}

int bin(int x)
{
    int l=1,r=10000000000,mid;
    while(l<=r)
    {
        mid=(l+r)/2;
        if(x<=nrz(mid))
            r=mid-1;
        else
            l=mid+1;
    }
    return l;
}

int main(){
    int n,p;
    ifstream in("fact.in");
    ofstream out("fact.out");
    in>>p;
    n=bin(p);
    if(nrz(n)==p)
        out<<n;
    else
        out<<"-1";
    in.close();
    out.close();
    return 0;
}