Cod sursa(job #2756492)

Utilizator GustFlorin Sausage Gust Data 1 iunie 2021 01:52:32
Problema Factorial Scor 90
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <stdio.h>
#include <math.h>

const int range = 50;

int nrzerofact(int n){
    int maxim = 0;
    int copie = n;
    while(copie) {
        copie = copie/5;
        maxim++;
    }
    int suma=0;
    for(int i=1; i<maxim; i++){
        suma+=n/pow(5,i);
    }
    return suma;
}

int main() {
    FILE *in = fopen("fact.in", "r");
    FILE *out = fopen("fact.out", "w");
    int P;
    fscanf(in, "%d", &P);
    if(P==0){
        fprintf(out, "%d", 1);
    }else {
        int k = P / 5 - range;
        if (k < 0)k = 0;
        while (nrzerofact((P - k) * 5) != P) {
            k++;
        }
        fprintf(out, "%d", (P - k) * 5);
    }
}