Cod sursa(job #1324869)

Utilizator Eugen_VlasieFMI Vlasie Eugen Eugen_Vlasie Data 22 ianuarie 2015 21:07:34
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>

using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n,i,j,p;
int cautbin(long long a,long long b)
{
    if(a>b)
        return -1;
    int m=(a/5+b/5)/2;
    m*=5;
    int x=5;
    int pa,pb,pm;
    pa=pb=pm=0;
    while(a/x!=0)
    {
        pa+=a/x;
        x*=5;
    }
    x=5;
    while(b/x!=0)
    {
        pb+=b/x;
        x*=5;
    }
    x=5;
    while(m/x!=0)
    {
        pm+=m/x;
        x*=5;
    }
    x=5;
    if(pm>n)
        return cautbin(a,m-5);
    else
        if(pm<n)
            return cautbin(m+5,b);
        else
            return m;
}
int main()
{
    f>>n;
    if(n==0)
        g<<"1"<<'\n';
    else
    {
        g<<cautbin(0,n*5)<<'\n';
    }
    return 0;
}