Cod sursa(job #1587866)

Utilizator MarlowTroneci Andreea Marlow Data 2 februarie 2016 17:17:41
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nz(int x)
{
    int ans=0,p5=5;
    while(x>=p5)
    {
        ans=ans+x/p5;
        p5=p5*5;
    }
    return ans;
}
int main()
{
    int p,st,dr;
    cin>>p;
    st=1;dr=500000000;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if(nz(mij)<p)
            st=mij+1;
        else
            dr=mij-1;
    }
    if(nz(st)==p)
        cout<<st;
    else
        cout<<-1;
    return 0;
}