Cod sursa(job #3317120)

Utilizator RegeleOu3433Calin V. Dragos Andrei RegeleOu3433 Data 22 octombrie 2025 11:30:47
Problema Factorial Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <stdio.h>
#define MAXP5 1490116119384765625LL

int main () {
    FILE *fin , *fout;
    long long p , stn , drn , mijn , p5n , zeron;
    
    fin = fopen ( "fact.in" , "r" );
    fscanf ( fin , "%lld" , &p );
    fclose ( fin );
    
    stn = 0;
    drn = 5000000000000000000;
    while ( drn - stn > 1 ) {
        mijn = ( stn + drn ) / 2;
        p5n = MAXP5;
        zeron = 0;
        while ( p5n > 1 ) {
            zeron = zeron + mijn / p5n;
            p5n = p5n / 5;
        }
        if ( zeron < p )
            stn = mijn;
        else
            drn = mijn;
    }
    
    fout = fopen ( "fact.out" , "w" );
    p5n = MAXP5;
    zeron = 0;
    while ( p5n > 1 ) {
        zeron = zeron + drn / p5n;
        p5n = p5n / 5;
    }
    if ( zeron == p ) 
        fprintf ( fout , "%lld" , drn );
    else
        fprintf ( fout , "-1" );
    fputc ( '\n' , fout );
    fclose ( fout );
    
    return 0;
}