Cod sursa(job #1934046)
| Utilizator | Data | 21 martie 2017 08:48:34 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1 kb |
#include <iostream>
#include <cstdio>
using namespace std;
FILE*fin=fopen("fact.in","r");
FILE*fout=fopen("fact.out","w");
int main()
{
int n , p , k = 0 , x , i , k1 = 0 , j ;
cin >> p ;
for ( i = 1 ; i <= p * 5 ; ++i )
{
if ( i % 5 == 0 )
{
x = i ;
if ( ( i / 5 ) % 5 == 0 )
{
while ( x % 5 == 0 )
{
++k ;
x /= 5 ;
}
}
else ++k ;
if ( k >= p ) break ;
}
}
n = i ;
for ( j = 5 ; j <= n ; ++j )
{
if ( j % 5 == 0 )
{
x = j ;
if ( ( j / 5 ) % 5 == 0 )
{
while ( x % 5 == 0)
{
++k1 ;
x /= 5 ;
}
}
else ++k1 ;
}
}
if ( k1 == p ) cout << i ;
else cout << "-1" ;
return 0;
}
