Cod sursa(job #2073651)
| Utilizator | Data | 23 noiembrie 2017 15:07:45 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int v[801];
int fact(int x){
int suma=0,p=5;
while(x/p>0){
suma+=x/p;
p*=5;
}
return suma;
}
int main(){
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int putere,s,p;
scanf("%d",&p);
putere=1<<30;
s=0;
while(putere>0){
if(fact(s+putere)<=p-1)
s+=putere;
putere/=2;
}
if(fact(s+1)==p)
printf("%d",s+1);
else
printf("-1");
return 0;
}
