Cod sursa(job #3230867)

Utilizator tudorhTudor Horobeanu tudorh Data 23 mai 2024 09:41:06
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>

using namespace std;
int v[100001],n;
bool check(int val,int target)
{
    int p5=5,cnt=0;
    while(p5<=val)
    {
        cnt+=val/p5;
        p5*=5;
    }
    return (cnt>=target);
}
int cb(int val)
{
    int st=1,dr=1e8*5,mid,rasp;
    while(st<=dr)
    {
        mid=(st+dr)/2;
        if(check(mid,val))
        {
            rasp=mid;
            dr=mid-1;
        }
        else st=mid+1;
    }
    return rasp;
}
int main()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");

    int p;
    fin>>p;
    fout<<cb(p);
    return 0;
}