Cod sursa(job #550399)

Utilizator RampageSergiu Caraian Rampage Data 9 martie 2011 14:37:21
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
using namespace std;

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

int main()
    {
    float p,s=0;
    int j,a=0,b=200,x;
    bool flag=false;
    f>>p;
	if (p==0)
		g<<-1;
	else
	{
	while (flag!=true)
        {
        s=0;
        x=(a+b)/2;
        for (int i=0; i<=x && s<=p+1 ; i+=5)
            {
            j=i;
            if (j!=0)
				while (j%5==0)
                {
                s++;
                j/=5;
                }
            }
        if (s==p)
            flag=true;
        else
            if (s<p)
                a=x;
            if (s>p)
                b=x;
        }
	while (x%5!=0)
		x--;	
		g<<x;
    }
	g.close();
    return 0;
    }