Cod sursa(job #48892)

Utilizator deltaDumitrache Mircea delta Data 5 aprilie 2007 10:19:24
Problema Numere 2 Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <fstream.h>
#include <math.h>

unsigned long int n;




int main()
{
	ifstream fin("numere2.in");
	ofstream fout("numere2.out");


	fin >> n;
	int cont;
	int ok = 1;
	int exp;


	if (n == 2) fout << 2 << "\n" << 1;
	if (n == 3) fout << 3 << "\n" << 1;
	if (n %2 == 0)
	{
		int exp1 = 1;
		for (int j = 2; j * j <= n; j+=2)
		{
			cont = 0;
			int ok1 = 0;
			while (pow(j, exp1) < n)
			{
				if (pow(j, exp1) == n)
					ok1 = 1;
				exp1++;
			}
			if (ok1)
			{
				fout << j << "\n" << exp1-1;
				cont = 1;
				break;
			}
		}
	}




	else
	{

		for (int i = 3; i * i <= n; i+=2)
		{
			cont = 0;
			if (n %i == 0)
			{
				exp = 1;
				ok = 1;
				while (pow(i,exp) <= n)
				{
					if (n == pow(i,exp))
						ok = 0;
					exp++;
				}
			}
			if (ok == 0)
			{
				fout << i << "\n" << exp -1;
				cont = 1;
				break;
			}
		}
	}


	if (cont == 0)
		fout << n << "\n" << 1;

	fin.close();
	fout.close();
	return 0;
}