Pagini recente » Atasamentele paginii Profil songoku_blond | Monitorul de evaluare | Ghid pentru scriere unei surse in MinGW Developer Studio | Cod sursa (job #2425372) | Cod sursa (job #2686043)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;
typedef unsigned long ulong;
typedef unsigned int uint;
uint count_factor(uint n, uint factor) {
// count the how many times "factor" occurs
// in the factor decomposition of n
uint count = 0;
while (n != 0 && n % factor == 0) {
n /= factor;
count++;
}
return count;
}
// find n
// where n is the smallest numbers
// for which n! ends with the given number of zeroes
uint find_sol(uint zeroes) {
uint count2 = 0;
uint count5 = 0;
uint n = 0;
while (min(count2, count5) < zeroes) {
count2 += count_factor(n, 2);
count5 += count_factor(n, 5);
n++;
}
return n - 1;
}
int main(int argc, char** argv) {
// read the number of zeroes from file
ifstream f("fact.in");
uint zeroes;
f >> zeroes;
ofstream out("fact.out");
out << find_sol(zeroes);
return 0;
}