Cod sursa(job #1520555)

Utilizator ArmandNMArmand Nicolicioiu ArmandNM Data 9 noiembrie 2015 00:41:54
Problema Factorial Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <iostream>

using namespace std;

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

int N, P;
int nr;

int zeroes(int x)
{
    int ans = 0;
    int pow = 5;

    while (pow <= x)
    {
        ans += x / pow;
        pow *= 5;
    }

    return ans;
}

int cautare(int P)
{
    int ls = 1;
    int ld = 10000000;

    while (ls <= ld)
    {
        int mid = (ls + ld) / 2;
        if (zeroes(mid) >= P)
        {
            ld = mid - 1;
        }
        else
        {
            ls = mid + 1;
        }
    }

    return ls;
}

int main()
{
    f >> P;

    nr = cautare(P);

    if(zeroes(nr) == P)
    {
        g << nr << '\n';
    }
    else
    {
        g << "-1\n";
    }

    return 0;
}