Cod sursa(job #1707451)

Utilizator andrew1312Okukura Andrew-Hiroaki andrew1312 Data 25 mai 2016 08:38:26
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    long long a=61035156,p,n=1,x=244135625,k=5;
    fin>>p;
    while (p>0)
    {
        if (p>=a&&k>0) {p-=a;n+=x;k--;}
        else if (k>0) {a-=1;a/=5;x/=5;k=5;}
        else {p=-1;}
    }
    cout<<p;
    if (p==0) fout<<n;
    else fout<<"-1";
    return 0;
}