Cod sursa(job #1789824)

Utilizator adivd15Costea Adrian adivd15 Data 27 octombrie 2016 15:43:23
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

long st=1,dr,mij,aux,p;

int zeroes(long n)
{
    long long power=5;
    int result=0;
    int add;
    while(add=int(n/power))
    {
        result+=add;
        power=power*5;
    }
    return result;
}

int main()
{

    f>>p;
    dr=5*p;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        aux=zeroes(mij);
        //g<<st<<" ";
        if(aux<p) st=mij+1;
        if(aux>=p) dr=mij-1;
    }

    if(zeroes(st)==p) g<<st;
    else g<<-1;
    return 0;
}