Pagini recente » Cod sursa (job #1325864) | Cod sursa (job #1879658) | Cod sursa (job #1583344) | Cod sursa (job #2273223) | Cod sursa (job #1704485)
//package factorial;
import java.util.*;
import java.io.*;
/***
*
* @author Patrick
*
*/
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner scanner = new Scanner(new BufferedInputStream(new FileInputStream("fact.in")));
long P = scanner.nextLong() ;
PrintStream output = new PrintStream(new FileOutputStream("fact.out"));
if ( P == 0 ) {
output.print( 1 );
return ;
}
long st = 1 ;
long dr = 1000000014 ;
long solutie = -1 ;
while ( st <= dr ) {
long mij = ( st + dr ) / 2 ;
if ( nrzero ( mij ) >= P ) {
solutie = mij ;
dr = mij - 1 ;
}
else {
st = mij + 1 ;
}
}
if ( solutie == -1 ) {
output.print ( solutie ) ;
}
else if ( nrzero ( solutie ) != P ) {
output.print ( -1 ) ;
}
else {
while ( solutie % 5 != 0 ) {
solutie = solutie - 1 ;
}
output.print ( solutie ) ;
}
}
public static long nrzero ( long a )
{
long p = 5 ;
long s = 0 ;
while ( a / p != 0 ) {
s = s + a / p ;
p *= 5 ;
}
return s ;
}
}