Cod sursa(job #892124)

Utilizator margikiMargeloiu Andrei margiki Data 25 februarie 2013 22:25:02
Problema Factorial Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int main()
{
    int k,p,n,pow;
    f>>p;
    n = 4*p;
    k=0;
    pow=5;
    while(n/pow)
      {
          k += n/pow;
          pow *= 5;
      }
    n=n+5;
    do {
        pow = 5;
        k = 0;
        while(n/pow) {
                        k += n/pow;
                        pow *= 5;
                     }
        n += 5;
    } while(k < p);
    n -= 5;
    if(p == 0) g<<1;
    else if(k == p) g<<n<<"\n";
         else g<<-1<<"\n";

    return 0;
}