Cod sursa(job #1974903)

Utilizator RaresEGaySopterean Adrian RaresEGay Data 29 aprilie 2017 12:18:28
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <limits.h>

using namespace std;

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

long long p;
long long sum;

int main(){
    f >> p;

    if(!p){
        g << 1 << '\n';
        return 0;
    }
    for(long long i = 5; i <= LLONG_MAX; i += 5){
        if (i % 5 == 0){
            long long k = i;
            while(k % 5 == 0){
                ++sum;
                k /= 5;
            }
        }
        if (p == sum){
            g << i << '\n';
            break;
        }
        else if(sum > p){
            g << -1 << '\n';
            break;
        }
    }

}