Cod sursa(job #1004301)

Utilizator impulseBagu Alexandru impulse Data 2 octombrie 2013 15:54:19
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
//
//  main.cpp
//  ex2
//
//  Created by Alexandru Bagu on 02.10.2013.
//  Copyright (c) 2013 Alexandru Bagu. All rights reserved.
//

#include <iostream>
#include <fstream>
using namespace std;
typedef long long int ulint;
int main(int argc, const char * argv[])
{
    ifstream fin("fact.in");
    int k;
    fin>>k;
    ulint max = k * 5;
    ulint pMax = max;
    ulint p = 25;
    ulint o = 2;
    while(true)
    {
        if(max < p) break;
        else
        {
            ulint p2 = p;
            int i = 1;
            do {
                pMax -= o;
                i++;
                p2 = p * i;
            } while(p2 < max);
        }
        o++;
        p *= 5;
    }
    ofstream fout("fact.out");
    while(pMax % 5 != 0) pMax --;
    fout<<pMax<<endl;
    return 0;
}