Mai intai trebuie sa te autentifici.
Cod sursa(job #1748746)
Utilizator | Data | 26 august 2016 19:02:35 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.68 kb |
#include <stdio.h>
#define MAX 1000000000
int cinci(long long p)
{
int pow = 1, s = 0;
while ( pow * 5 <= p)
{
pow *= 5;
s += p/pow;
}
return s;
}
long long caut_bin(long long a, long long b, int p)
{
long long mid;
while( b - a > 1)
{
mid = (b + a) / 2 ;
if (cinci(mid) < p)
a = mid;
else
b = mid;
}
if(cinci (b) == p)
return b;
else
return -1;
}
int main(void)
{
long long p;
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
scanf("%lld", &p);
printf("%lld \n", caut_bin(0,MAX,p));
}