Cod sursa(job #1793444)

Utilizator cjalex13Cioarec Alexandru Marian cjalex13 Data 31 octombrie 2016 00:24:14
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include <fstream>
using namespace std;

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

unsigned int nrZero(unsigned int x){
    unsigned int y=5;
    unsigned int sum =0;
    while(x/y != 0){
        sum += x/y;
        y = y*5;

    }
    return sum;
}

int main()
{
    unsigned int nrDeZero;

    f>>nrDeZero;

    unsigned int d,s,x;
    s=1;
    d=1000000000;
    long long a;
    while( s < d){
        a=(s+d)/2;
        if(nrDeZero < nrZero(a)){
            d=a-1;
        }
        else if(nrDeZero > nrZero(a)){
            s=a+1;
        }
        else{
            x=a;
            x = x - x%5;
            if(x==0){
                x=1;
            }
            g<<x;
            return 0;
        }
    }

    g<<0;


    return 0;
}