Cod sursa(job #1701294)

Utilizator Belu99Bibo Bela Belu99 Data 12 mai 2016 17:43:17
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.81 kb
#include <iostream>
#include <fstream>
using namespace std;
int x=24,s=0,n=0,p,ok=0,i=1;
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    if(p>x)
    {
    while(x<p)
        x=x*10;
    while(x>=24)
    {
        if(s+x<=p)
            {
                if(s+x==p)
                {
                    g<<(s/24)*100;
                    return 0;
                }
                s+=x;
                ok++;
            }
        else
            {
                if(ok>0)
                    s-=x;
                x/=10;
                ok=0;
            }
    }
    x=18;
    n=(s/24)*100;
    while(x>=6)
    {
        if(s+x<=p)
        {
            n+=25*(x/6);
            if(s+x==p)
               {
                   g<<n;
                   return 0;
               }
            s+=x;
            ok++;
        }
        else
            {
                if(ok>0)
                    s-=x;
                x-=6;
                ok=0;
            }
    }
    x=4;
    while(x>=1)
    {
        if(s+x<=p)
        {
            n+=5*x;
            if(s+x==p)
            {
                g<<n;
                return 0;
            }
            s+=x;
            ok++;
        }
        else
            {
                if(ok>0)
                    s-=x;
                x--;
                ok=0;
            }
    }
    }
    else
    if(p==0)
        g<<0;
    else
    {
        s=5,ok=0;
        while(i<p)
        {
            s=s+5;
            x=s;
            while(x%5==0)
            {
                i++;
                x/=5;
            }
            if(i>p)
                ok++;
        }
        if(ok==0)
            g<<s;
        else
            g<<-1;
        }
    return 0;
}