Cod sursa(job #2336805)
| Utilizator | Data | 5 februarie 2019 16:12:45 | |
|---|---|---|---|
| Problema | Factorial | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int n, p, st=1, dr=100000000, mij, x, v, a;
int main()
{
in>>p;
while(st<dr){
mij=(st+dr)/2;
x=mij;
n=0;
while(x){
x/=5;
n+=x;
}
if(n>=p){
dr=mij;
}else{
st=mij+1;
}
}
v=dr, a=0;
while(v){
v/=5;
a+=v;
}
if(a==p){
out<<dr;
}else{
out<<-1;
}
}
