Cod sursa(job #1942013)

Utilizator cosminbxCosmin Banu cosminbx Data 27 martie 2017 19:02:17
Problema Factorial Scor 35
Compilator c Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main(void)
{
    int ret = 0;

    FILE *fin = NULL;
    FILE *fout = NULL;

    fin = fopen("fact.in", "r");
    if (fin == NULL) {
        ret = -1;
        goto exit;
    }

    int32_t p;
    if (fscanf(fin, "%" PRIu32, &p) != 1) {
        ret = -1;
        goto exit;
    }

    uint32_t n = 1;
    while (p > 0) {
        n++;
        uint32_t nn = n;
        while (nn % 5 == 0) {
            nn /= 5;
            p--;
        }
    }

    fout = fopen("fact.out", "w");
    if (fout == NULL) {
        ret = -1;
        goto exit;
    }

    if (p < 0) {
        fprintf(fout, "%d", -1);
    } else {
        fprintf(fout, "%" PRIu32, n);
    }

exit:

    if (fin != NULL) {
        fclose(fin);
    }
    if (fout != NULL) {
        fclose(fout);
    }

    return ret;
}