Cod sursa(job #1734531)

Utilizator MihalachiRazvanMihalachi Razvan MihalachiRazvan Data 27 iulie 2016 16:44:13
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,n,i;
int putere5(int n)
{
    int k=0;
    while((pow(5,k))<n)
    {
        k=k+1;
    }
    if(k<2)
        return 0;
    else
        return k;
}
int scadere(int p)
{
    int aux,y,x,k=1;
    x=6;
    y=5;
    while(x+y<p)
    {
        y=y+x;
        k++;
    }
    if(x+y==p||p==5)
        return 0;
    else
         return k;

}
int main()
{
    fin>>p;
      if(p==0)
        fout<<1;
        else if(p==1)
        fout<<5;
        else
        {
            n=p*5;
            if(scadere(p)==0)
                fout<<-1;
                else
                fout<<n-(5*(scadere(p)));



        }

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