Cod sursa(job #1107212)
| Utilizator | Data | 13 februarie 2014 18:34:45 | |
|---|---|---|---|
| Problema | Factorial | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 kb |
#include <fstream>
#define MAX 50000000
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long p;
int zero(int k){
long m = 5, z = 0;
while(k/m != 0){
z+=k/m;
m*=5;
}
return z;
}
int bin_search(int a, int b){
long c = (a+b)/2;
if(zero(c) < p){
bin_search(c+1, b);
}else if(zero(c) > p){
bin_search(a, c-1);
}else{
return c;
}
}
int main()
{
f>>p;
if(p==0){
g<<1;
}else if(p==5){
g<<-1;
}else{
long n = bin_search(0, MAX);
while(zero(n-1)==p){
n=n-1;
}
g<<n;
}
return 0;
}
