Cod sursa(job #1720543)

Utilizator ze_coderPop Ioan ze_coder Data 22 iunie 2016 18:46:56
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include <fstream>


using namespace std;

int pow5(int);
int main()
{
    long p;
    int i,n,x;
    n = 1;
    i = 1;
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    fin >> p;
    while (p > 0){
        n = i * 5;
        x = pow5(i);
        p = p -x -1;
        i++;
    }

    if (p == 0)
        fout << n;
    else fout << -1;

    return 0;
}

int pow5(int x){
    int exp = 0;
    while (x % 5 == 0){
        exp++;
        x = x/5;
    }
    return exp;
}