Cod sursa(job #765717)

Utilizator DorelBarbuBarbu Dorel DorelBarbu Data 9 iulie 2012 00:58:57
Problema Factorial Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>
using namespace std;
int gaseste5(int x)
{
    int nr5=0,i,div=5,c;
    do
    {
        c=x/div;
        nr5+=c;
        div*=5;
    }while(div<=x);
    return nr5;
}
int main()
{
    ifstream in("fact.in");
    ofstream out("fact.out");
    int st=1, dr=10000000,k,n,m;
    bool gasit=false;
    in>>n;
    dr=n*5;
    if(n)
    {
        while(st<=dr && gasit==false)
        {
            k=(st+dr)/2;
            m=gaseste5(k);
            if(m==n) gasit=true;
            else if(m<n) st=k+1;
            else dr=k-1;
        }
        if(gasit==true)
        {
            if(k%5) out<<k-k%5;
        }
        else out<<-1;
    } else out<<1;
    return 0;

}