Cod sursa(job #361900)

Utilizator TFifesPorcescu Alexandru TFifes Data 7 noiembrie 2009 06:04:44
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<iostream>
#include<fstream>
#include<math.h>
using namespace std;
unsigned  long long x[13]={5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125},i;

long cautare(unsigned  long a,unsigned  long b,unsigned long s)
{
    unsigned long  d;
     long max=-1;
    unsigned long v;
    while(a<=b)
    {
        d=(a+b)/2;
        v=0;
        for(i=0;x[i]<=d;i++)
        {
            v+=d/x[i];
        }
        if(v==s)
        {
        max=d;
        b=d-1;
        }
        else if(v>s)
        b=d-1;
        else
        a=d+1;
    }

    return max;

}
int main ()
{
    ifstream x("fact.in");
    ofstream y("fact.out");
    unsigned long p,a,b;
    x>>p;
    a=0;
    b=1000000000;
    y<<cautare(a,b,p);
    x.close();
    y.close();
    return 0;
    }