Pagini recente » Cod sursa (job #1990056) | Cod sursa (job #1714980) | Cod sursa (job #52291) | Cod sursa (job #2023690) | Cod sursa (job #446532)
Cod sursa(job #446532)
#include <stdio.h>
#include <math.h>
int p;
int nrcinci(long long n)
{
int rez=0,i;
for (i=1;i<=14;i++)
rez+=n/pow(5,i);
return rez;
}
int cauta(long long n1,long long n2)
{
//printf("%d %d\n",n1,n2);
if (n1==n2)
{
//printf("n1 = %d\n",n1);
if (nrcinci(n1)==p)
return n1;
else
return -1;
}
long long aux=(n1+n2)/2;
if (nrcinci(aux)==p)
return aux;
if (nrcinci(aux)<p)
return cauta(aux+1,n2);
return cauta(n1,aux);
}
int main()
{
FILE *in,*out;
in=fopen("fact.in","r");
out=fopen("fact.out","w");
fscanf(in,"%d",&p);
//p=10;
int n=floor(log(4*p+1)/log(5));
long long N1=pow(5,n); // <5^13
long long N2=pow(5,n+1);
//printf("%d %d\n",N1,N2);
long long rez=cauta(N1,N2);
//printf("%d \n\n",cauta(N1,N2));
//printf("%d ",nrcinci(9765625));
//getchar();
fprintf(out,"%lld",rez);
return 0;
}
/*
25 6
125 31
625 156
3125 781
15625 3906
78125 19531
390625 97656
1953125 488281
9765625 2441406
48828125 12207031
244140625 61035156
1220703125 305175781
*/