Cod sursa(job #1749704)

Utilizator Mircea_DonciuDonciu Mircea Mircea_Donciu Data 28 august 2016 16:40:23
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

using namespace std;
long long p,st,dr,m;
int functie(int x)
{
    int s;
    s=0;
    while(x)
    {
        x/=5;
        s+=x;
    }
    return s;
}
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    st=3*p+1;
    dr=5*p+1;
    while(st+1<dr)
    {
        m=(st+dr)/2;
        if(functie(m)>=p) dr=m;
        else st=m;
    }
    if(functie(st)==p) g<<st<<'\n';
    else g<<dr<<'\n';
    f.close(); g.close();
    return 0;
}