Cod sursa(job #1733766)

Utilizator MihalachiRazvanMihalachi Razvan MihalachiRazvan Data 25 iulie 2016 17:49:21
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,n,i;
int verificare(int p)
{
    int ver=1;
    while(ver==1&&p!=1)
    {

        if(p%5==0)
            p=p/5;
        else
            ver=0;
    }
    if(ver==1)
        return 1;
    else
        return 0;
}
int putere5(int p)
{
  int k=1;
  while((pow(5,k))<p)
        k=k+1;
        if(k==1)
            return k;
        else
            return k-1;
}
int main()
{
    fin>>p;
      if(p==0)
        fout<<1;
        else if(p==1)
        fout<<5;
    else if(verificare(p)==1)
        fout<<-1;
        else
        {
            n=p*5;
            if(p>5*putere5(p))
                fout<<n-5*putere5(p);
            else
                fout<<n;

        }

    fin.close();
    fout.close();
    return 0;
}