Cod sursa(job #2554302)

Utilizator stefan123Rosca Stefan stefan123 Data 22 februarie 2020 19:42:28
Problema Factorial Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include<iostream>
#include<fstream>
#include<limits.h>

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

//int find_nr_0(int n)
//{
//	
//	int aux = 5;
//	int nr = 0;
//	while (n >=aux)
//	{
//		nr += n / aux;
//		aux *= 5;
//	}
//	return nr;
//}
//int find_number(int n)
//{
//	if (n == 0)
//	{
//		return 1;
//	}
//	int left = 1, right = 2000000000;
//	while (left<right)
//	{
//		int m = (left + right) / 2;
//		int aux = find_nr_0(m);
//		if (aux == n)
//		{
//			return m-m%5;
//		}
//		else
//		{
//			if ( aux < n)
//			{
//				left = m + 1;
//			}
//			else
//			{
//				right = m - 1;
//			}
//		}
//	}
//	return -1;
//}
int main()
{
	std::fstream in;
	int n;
	in.open(fin, std::ios::in);
	in >> n;
	in.close();
	int res = 0;
	std::fstream out;
	out.open(fout,std::ios::out);
	if (n == 0)
	{
		res = 0;
	}
	else
	{
		if(n%6==5)
		{
			res = -1;
		}
		else
		{
			int c = n / 6;
			res = (n - c) * 5;
		}
	}
	out << res;
	out.close();
	return 0;
}