Cod sursa(job #2449215)

Utilizator SpatialARTNuna David SpatialART Data 18 august 2019 17:18:14
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");
int how_many(int N)
{
    int zeros=0;
    while(N/5)
    {
        zeros+=N/5;
        N/=5;
    }
    return zeros;
}
int main()
{
    int P,ans=-1;
    f>>P;
    int st=1,dr=4e8+15,mid=0;
    cout<<dr;
    while(st<=dr)
    {
        mid=(st+dr)/2;
        if(how_many(mid)==P)
        {
            ans=mid;
            dr=mid-1;
        }
        else if(how_many(mid)>P)
            dr=mid-1;
        else
            st=mid+1;
    }
    g<<ans;
}