Cod sursa(job #1978360)

Utilizator florin.elfusFlorin Elfus florin.elfus Data 7 mai 2017 16:00:07
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;
int nz(int n)
{
    int q=0,x=5;
    while (n>=x)
    {
        q=q+(n/x);
        x=x*5;
    }
    return q;
}
int main() {
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    int p;
    fin >> p;
    int st = 1;
    int dr = 5 * p + 100;
    int rasp = -1;
    while (st <= dr) {
        int m = (st + dr) / 2;
        if (nz(m) == p) {
            rasp = m;
            dr = m - 1;
        }
        if (nz(m) < p)
            st = m + 1;
        if (nz(m) > p)
            dr = m - 1;
    }
    fout << rasp;
    return 0;
}