Cod sursa(job #2505518)
| Utilizator | Data | 6 decembrie 2019 23:12:17 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int nrciffact(long long int n){
int s=0;
for (int i=5;i<=n;i*=5) s+=n/i;
return s;
}
int main(){
int p;
in>>p;
long long int sf=100000000000,inc=0,mij,poz;
bool ok=1;
while (inc <=sf&& ok){
mij=(inc+sf)/2;
int x=nrciffact(mij);
if (x<p)inc=mij+1;
else if (x>p) sf=mij-1;
else poz=mij-1,ok=0;
}
out<<poz;
}
