Cod sursa(job #550402)

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

int main()
    {
    ifstream f ("fact.in");
	ofstream g ("fact.out");
	float p,s=0;
    int j,a=0,b=200,x;
    bool flag=false;
    f>>p;
	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--;	
    if (p==0) g<<1;
	else g<<x;
	
	g.close();
    return 0;
    }