Cod sursa(job #1753760)

Utilizator MihalachiRazvanMihalachi Razvan MihalachiRazvan Data 7 septembrie 2016 09:58:24
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
unsigned long long a,b,c,k,k2,s=0;
unsigned long long int  nrzerouri(unsigned long long int x)
{
    unsigned long long int k1=0;
    while(x%10==0)
    {
        k1++;
        x=x/10;
    }
    return k1;
}
int main()
{

    fin>>k;
    if(k==0)
        fout<<1;
    else if(k==1)
        fout<<5;
    else
    {
        a=2;
        b=4;
        c=5;
        k2=1;
            while(s<k)
        {

            s=s+nrzerouri(a*b*c);
            if(k2==1&&s!=k)
            {
                a=a+4;
                b=b+4;
                c=c+5;
                k2=2;
            }
            else if(k2==2&&s!=k)
            {
                a=a+6;
                b=b+6;
                c=c+5;
                k2=1;
                }

            }
        }
         if(s==k)
            fout<<c;
         else
            fout<<-1;
    fin.close();
    fout.close();
    return 0;
}