Cod sursa(job #1115639)

Utilizator carlaflorianFlorian Carla Narcisa carlaflorian Data 21 februarie 2014 22:13:43
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>
#include <climits>
using namespace std;

int zero(int n)
{
    int s=0, p=5;
    while(n/p>0)
    {
        s=s+n/p;
        p=p*5;
    }
    return s;
}

int main()
{
   ifstream f("fact.in");
   ofstream g("fact.out");

   int n=INT_MAX,i,y,x,xx,p;
   bool ok=1;

   f>>p;

   i=1; y=n;
   if(p==0)
        g<<1;
   while(i<=y)
       {
            x=(i+y)/2;
            if(zero(x)==p)
            {
                ok=1;
                for(xx=x; xx>1; xx--)
                    if(zero(xx)!=p)
                        break;
                g<<xx+1;
                break;
            }
        else
            if(p>zero(x))
                i=x+1;
            else
                y=x-1;
       }
    if(ok==0)
        g<<-1;
}