Cod sursa(job #2968872)

Utilizator adimiclaus15Miclaus Adrian Stefan adimiclaus15 Data 22 ianuarie 2023 11:49:54
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<iostream>
#include<fstream>
using namespace std;

int nz(int n)
{
    int p = 5, nr = 0;
    while(p<=n)
    {
        nr+=n/p;
        p*=5;
    }
    return nr;
}

int cb(int k)
{
    int st = 1, dr = 5 * k + 5, poz = -1;
    while(st<=dr)
    {
        int mij = (st + dr)/2;
        if(nz(mij) < k)
        {
            st = mij + 1;
        }
        else
        {
            dr = mij - 1;
            poz = mij;
        }
    }
    if(nz(poz) == k) {
        return poz;
    } else {
        return -1;
    }
}

//cel mai mic poz pt care poz! >= k

int main()
{
    int p;
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    g<<cb(p);
}