Cod sursa(job #2720581)

Utilizator pasqualePascale Radu-Ioan pasquale Data 11 martie 2021 00:12:30
Problema Factorial Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <stdio.h>
#include <math.h>

int fact(int p);
int sumare(long long n);

int main(){
    int p;
    FILE *f;
    f=fopen("fact.in", "r");
    fscanf(f, "%d", &p);
    fclose(f);
    f=fopen("fact.out", "w");
    fprintf(f, "%d", fact(p));
    fclose(f);
    return 0;
}

int fact(int p){
    int sum;
    long long n=4*p;
    while(n%5!=0){
        n++;
    }
    while(p){
    sum=sumare(n);
    if(sum>p){
        return -1;
    }
    else if(sum == p){
        return n;
    }
    else{
        n+=5;
    }
    }
    return 1;
}

int sumare(long long n){
    int i=1, rez=0;
    while(n>=pow(5,i)){
        rez+=floor(n/pow(5,i));
        i++;
    }
    return rez;
}