Mai intai trebuie sa te autentifici.

Cod sursa(job #2076640)

Utilizator dey44andIoja Andrei-Iosif dey44and Data 26 noiembrie 2017 21:26:06
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int caut(long v)
{
    int zerouri  = 0;
    while(v)
    {
        zerouri+=(v/=5);
    }
    return zerouri;
}

long long P, N;

int main()
{
    in >> P;
    long left = 0;
    long right = P*5;
    long solutie = -1;
    while(left<=right)
    {
        int mijloc = (left + right) / 2;
        int posibil = caut(mijloc);
        if(posibil>=P)
        {
            solutie = posibil;
            right = mijloc - 1;
        }
        else left = mijloc + 1;
    }
    out << solutie;
    return 0;
}