Cod sursa(job #2237515)

Utilizator vlad082002Ciocoiu Vlad vlad082002 Data 2 septembrie 2018 01:56:37
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>

using namespace std;

int main () {

     int p, n = 1, putere = 1, y = 5;
     bool gasit = false;

     ifstream in ("fact.in");
     in >> p;
     in.close();

     for (int i = 1; i <= p; i++) {
          putere *= 5;
     }

     do {
     
          n *= y;   

          if (n % putere == 0) {
               if (n % (putere * 5) == 0) {
                    ofstream out ("fact.out");
                    out << -1;
                    out.close(); 
               } else {
                    ofstream out ("fact.out");
                    out << n;
                    out.close();
               }
               gasit = true;
          }
          y += 5;
     } while (!gasit)

     return 0;
}