Cod sursa(job #1712612)

Utilizator andrew1312Okukura Andrew-Hiroaki andrew1312 Data 3 iunie 2016 09:20:49
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    long long a=305175781,p,n=0,x=1220703125,k=4,ok=0;
    fin>>p;
    if (p!=0) ok=1;
    while (p>0)
    {
        if (p>=a&&k>0) {p-=a;n+=x;k--;}
        else if (k>0||p<a) {a--;a/=5;x/=5;k=4;}
        else {p=-1;}
    }
    if (p==0&&ok==1) fout<<n;
    else if (p==0) fout<<'1';
    else fout<<"-1";
    return 0;
}