Cod sursa(job #2156301)

Utilizator YetoAdrian Tonica Yeto Data 8 martie 2018 17:12:37
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
using namespace std;
int p, n, i, j, cnt, x, k, pmax, mult;

int main () {
    ifstream fin ("fact.in");
    ofstream fout ("fact.out");
    fin>>p;
    n=5*p;
    k=1;
    while (k<=n) {
        k*=5;
        pmax++;
    }
    pmax--;
    if (pmax==1) {
        fout<<5*p;
        return 0;
    }

    for (i=pmax;i>=2;i--) {
        x=1;
        cnt=0;
        for (j=1;j<=i;j++)
            x*=5;
        ///fout<<x<<" ";
        mult=x;
        do {
            cnt++;
            x+=mult;
        } while (x<=n);

        cnt--;
        n-=cnt*5;
    }

    fout<<n;
    return 0;
}