Cod sursa(job #2614830)

Utilizator stanciucalinStanciu Calin stanciucalin Data 12 mai 2020 18:53:15
Problema Numarare triunghiuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

int P;

int count0(int n){

    int rez = 0;

    for(int k = 5; k <= n; k *= 5){

        rez += n / k;
    }

    return rez;
}

int main(){

    f>>P;

    int i = 1, j = 1000000000;

    while(i < j){

        int m = i + (j - i) / 2;

        if(count0(m) < P){

            i = m + 1;
        }
        else{

            j = m;
        }
    }

    if(count0(j) == P){

        g<<j;
    }
    else
        g<<"-1";

    return 0;
}