Cod sursa(job #1806008)

Utilizator botondkozmanKozman Botond botondkozman Data 14 noiembrie 2016 19:07:09
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    long long int P;
    f>>P;
    long long int fact=1, i=2;
    long long int db=0;
    if (P<=0)
        if (P<0) g<<-1;
        else g<<1;

    else {
        while (P!=db)
        {
            fact=fact*i;
            while (fact%10==0)
            {
                db++;
                fact=fact/10;
            }
            if (i>8)
            {
                int t=4;
                int y=0;
                int hatvany=1;
                while (t>0)
                {
                    y+=(fact%10)*hatvany;
                    fact=fact/10;
                    hatvany*=10;
                    t--;
                }
                fact=y;
            }
            cout<<fact<<" "<<i+1<<" ";
            cout<<db<<endl;
            i++;
        }
        g<<i-1;
    }
    g.close();
}