Cod sursa(job #2578195)

Utilizator AswVwsACamburu Luca AswVwsA Data 10 martie 2020 18:42:06
Problema Factorial Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int nrciffact(int n){
    int s=0;
for (int i=5;i<=n;i*=5) s+=n/i;
return s;
}
int main(){
    int p;
    in>>p;
 int sf=INT_MAX,inc=0,mij,poz=-1;
 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;
}