Cod sursa(job #1474858)

Utilizator Rocamadour1497Alexandru Martiniuc Rocamadour1497 Data 23 august 2015 02:41:05
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>
using namespace std;
int n,i,mij,s,j,p;
int zerouri (int x)
{
    int z=0;
    while(x)
        z+=x/5,x/=5;
    return z;
}
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    int st=1,dr=1000000010;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        if(zerouri(mij)<p) st=mij+1;
        else dr=mij-1;
    }
    if(zerouri(st)==p) g<<st;
    else g<<-1;
    f.close();
    g.close();
    return 0;
}