Cod sursa(job #3314653)

Utilizator sevescu_andreisevescu andrei sevescu_andrei Data 10 octombrie 2025 16:07:48
Problema Factorial Scor 90
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <stdio.h>
#include <stdlib.h>

int nr_zero(int n){
    int s=0;
    while(n>=5){
        s+=n/5;
        n/=5;
    }
    return s;
}

int main()
{
    FILE *fin, *fout;
    int dr,st,p,m,rez;
    fin=fopen("fact.in", "r");
    fout=fopen("fact.out", "w");
    st=0;
    dr=500000000;
    rez=-1;
    fscanf(fin, "%d" ,&p);
    while(st<=dr){
        m=(st+dr)/2;
        if(nr_zero(m)>=p){
            rez=m;
            dr=m-1;
        }
        else
            st=m+1;
    }
    if(nr_zero(rez)!=p)
        rez--;
    if(rez<1)
        rez=1;
    fprintf(fout, "%d" ,rez);
    return 0;
}