Cod sursa(job #3193657)

Utilizator RobertC2008123Cosac Robert-Mihai RobertC2008123 Data 15 ianuarie 2024 11:48:27
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
#include <climits>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int main ()
{
    int n, p;
    f >> p;
    if (p==0) g << 1;
    else {
    int st=1, dr=INT_MAX, retine=0;
    while (st<=dr)
    {
         int mij=st+(dr-st)/2;
         int nr5=5;
         int s=0;
         while (nr5<=mij)
         {
             s+=mij/nr5;
             nr5*=5;
         }
         if (s<=p)
         {

             retine=mij;
             st=mij+1;
         }
         else dr=mij-1;
    }
    g << retine-retine%5;
    }
}