Cod sursa(job #2449214)
Utilizator | Nuna David SpatialART | Data | 18 august 2019 17:12:42 |
---|---|---|---|
Problema | Factorial | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.57 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=1e8,mid=0;
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;
}