Cod sursa(job #2553748)

Utilizator stefan123Rosca Stefan stefan123 Data 22 februarie 2020 11:36:55
Problema Factorial Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<iostream>
#include<fstream>
#include<math.h>


#define fin "fact.in"
#define fout "fact.out"

int get_power(int n)
{
	int i = 0;
	bool ok = true;
	while(ok!=false)
	{
		int p = pow(5, i);
		if (n > p)
		{
			ok = true;
			i++;
		}
		else
		{
			ok = false;
		}
	}
	return i-1;
}

int main()
{
	std::fstream in,out;
	int n;
	in.open(fin, std::ios::in);
	in >> n;
	in.close();

	int res=0;
	out.open(fout, std::ios::out);
	int i = get_power(n);
	std::cout << i;
	if (n > 0)
	{
		res = (n-i) * 5;
	}
	if (n == 0)
	{
		res = 1;
	}
	out << res;
	out.close();

	return 0;
}