Cod sursa(job #806257)

Utilizator sinio1Stirbat Luca sinio1 Data 2 noiembrie 2012 14:47:48
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include<fstream>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int functia (int n)
{
    int puterea=0,ck=5;
    while (n/ck>=1)
    {
        puterea=n/ck+puterea;
        ck=ck*5;
    }
    return puterea;
}
//int zero (int n)
//{
  //  int s=0,x;
  //  x=5;
  //  while (n>=1)
   // {
     //   s=s+n/x;
       // n=n/x;
    //}
    //return s;
//}
int main ()
{
    int p,n,l1,l2,pp,z;
    f>>p;
    f>>n;
     l1=1;
    l2=1000000000;
    pp=0;
    while (l1<=l2&&pp==0)
    {
        n=(l1+l2)/2;
        z=functia(n);
        if (z==p)
        {
            pp=1;
            n=n-n%5;
        }
        else
        if (z<p)
            l1=n+1;
        else
            l2=n-1;
    }
    if (pp==0)
    g<<"-1";
    else
    if (pp==1)
    g<<n;
    if (p==0)
    g<<1;
    //g<<zero(n);
    f.close ();
    g.close ();
    return 0;
}