Cod sursa(job #1653604)

Utilizator andrew1312Okukura Andrew-Hiroaki andrew1312 Data 16 martie 2016 11:56:16
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    int p,k;
    long long n=25,n1;
    fin>>p;
    if (p==0) fout<<'1';
    else if (p<=5) fout<<p*5;
    else
    {
        p-=6;
        while (p>=4)
        {
            p-=4;n+=20;n1=n;
            for (;n1%5==0;k++,n1/=5) {}
            if (k>=p) {fout<<n;p=0;}
            else {p-=k;n+=5;}
        }
        if (p!=0) fout<<n+p*5;
    }
    return 0;
}