Pagini recente » Cod sursa (job #526375) | Cod sursa (job #1293012) | Cod sursa (job #233547) | Cod sursa (job #1159161) | Cod sursa (job #1329953)
# include <iostream>
# include <fstream>
int main () {
std :: ifstream f ("fact.in");
std :: ofstream g ("fact.out");
long P;
long nr = 0;
long i;
long a;
long nr1 ;
f >> P;
f.close ();
if ( P < 0 ) {
g << -1 << '\n' ;
g.close ();
return 0;
}
if ( P == 0 ) {
g << 1;
} else {
a = 5;
while (true) {
i = a;
nr += 5;
if ( i % 5 == 0 ) {
while ( i % 5 == 0 ) {
i /=5;
nr ++;
}
}
if ( nr == P ) {
g << a*5;
break;
} else if ( nr > P ) {
nr1 = 0;
i = a;
while ( i % 5 == 0 ) {
nr1 ++ ;
i /= 5;
}
if ( nr - nr1 - 1 == P ) {
g << ( a - 1) * 5;
break;
} else {
nr -= nr1;
a -= 1;
nr --;
while ( nr > P && a % 5 != 0 ) {
a --;
nr -- ;
}
if ( nr == P ) {
g << a*5;
break;
} else {
g << -1;
break;
}
}
}
a += 5 ;
}
}
g << '\n';
g.close ();
return 0;
}