Cod sursa(job #1941741)

Utilizator CYCodeDavid Bogdan CYCode Data 27 martie 2017 16:05:49
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <iostream>
#include <fstream>
#define Lmax 100000000

long unsigned P , n;
long int doiuri , cinciuri , ramas2 , ramas5;
long int numar[Lmax] , copie[Lmax];

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

void Citire_date()
{
    fin >> P;
    doiuri = 0;
    cinciuri = 0;
    n = 1;
    ramas2 = 2;
    ramas5 = 5;

    for(int i = 0 ; i < Lmax ; i++)
    {
        numar[i] = 0;
        copie[i] = 0;
    }
    return;
}

void Afisare(long unsigned numar)
{
    cout << n;
    return;
}

void Aflare_n()
{
    while(true)
    {
        if(n >= ramas2)
        {
            for(int i = ramas2; i <= n ; i+=2)
            {
                copie[i] = i;
                while(copie[i] % 2 == 0)
                {
                    doiuri++;
                    copie[i] = copie[i] / 2;
                }
            }
        }
        if(n >= ramas5)
        {
            for(int i = ramas5 ; i <= n ; i+=5)
            {
                copie[i] = i;
                while(copie[i] % 5 == 0)
                {
                    cinciuri++;
                    copie[i] = copie[i] / 5;
                }
            }
        }
        if(min(doiuri , cinciuri) == P)
        {
            Afisare(n);
            break;
        }
        else
        {
            n++;
        }
        ramas2 = (n + n%2);
        ramas5 = (n + n%5);
    }
    return;
}

int main()
{
    Citire_date();
    Aflare_n();

    return 0;
}