Mai intai trebuie sa te autentifici.
Cod sursa(job #1754375)
| Utilizator | Data | 8 septembrie 2016 00:15:43 | |
|---|---|---|---|
| Problema | Factorial | Scor | 25 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.75 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long func(long long n){
long long p=1,s=0;
while(p <= n){
p*=5;
s+=n/p;
}
return s;
}
int main()
{
long long st=1,dr = 1<<9;
long long mij;
bool gasit = false;
long long n0,p;
f >> p;
if(p == 0){
g << 1;
return 0;
}
while(st < dr && !gasit){
mij = (st + dr) / 2;
n0 = func(mij);
if(n0 == p) gasit = true;
else if(n0 < p) st = mij + 1;
else dr = mij - 1;
}
if(!gasit) g << -1;
else{
while(mij%5) mij--;
g << mij;
}
return 0;
}
