Cod sursa(job #390858)

Utilizator d_alexDraghici Alexandru d_alex Data 4 februarie 2010 18:25:03
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include<fstream>
using namespace std;
int nrz(int x)
{
	int y=0;
	while(x!=0)
	{
            x=x/5;
            y=y+x;
            }       
    return y;         
}
void sol(unsigned long int a,unsigned long int p,unsigned long b,unsigned long int &s)
{
    long m;
    if(b>a)
    {
           m=(a+b)/2;
           if(nrz(m)==p)
                        s=m;
                        else
                        if(nrz(m)<p)
                                    sol(m+1,p,b,s);
                        else
                            sol(a,p,m-1,s);
    }
}
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    unsigned long int p,s=0,c;
    f>>p;
    sol(0,p,1000000,s);
    if(s==0)
    g<<-1;
    else
    {
    c=s-1;
    while(nrz(c)==p)
    c--;
    g<<c+1;
    g<<nrz(44);}
    return 1;
}