Cod sursa(job #2078423)

Utilizator BaraianTudorBaraian Tudor Stefan BaraianTudor Data 29 noiembrie 2017 15:52:46
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <iostream>
#include<fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int main()
{
    int st,dr,x,p,s=0,mij,dr1;
    in>>p;
    st=1;
    dr=1000000000;
    while(st<dr)
    {
        mij=(st+dr)/2;
        x=mij;
        s=0;
        while(x)
        {
            s=s+x/5;
            x/=5;
        }
        if(s>=p)
            dr=mij;else st=mij+1;
    }
    dr1=dr;
    s=0;
    while(dr1)
    {
        s=+dr1/5;
        dr1/=5;
    }
    if(s==p)
    out<<dr;
    else
        out<<-1;
    return 0;
}