Cod sursa(job #1029310)

Utilizator MoneaVladMonea Vlad MoneaVlad Data 15 noiembrie 2013 12:44:29
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>

using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");

int factorial(int x){
    int S = 0;
    for(int i = 5; i <= x; i = i * 5)
        S = S + x / i;
    return S;
}

int main()
{
    int st, dr, mid, p;
    in >> p;
    st = 1;
    dr = 1000000000;
    while (dr - st > 1){
        mid = st + (dr - st) / 2;
        if (factorial (mid) >= p)
                    dr = mid;
                    else
                    st = mid;
    }
    if (factorial (st) == p)
        out << st;
        else
        out << dr;
}