Cod sursa(job #764374)

Utilizator UnforgivenMihai Catalin Botezatu Unforgiven Data 4 iulie 2012 22:22:29
Problema Frac Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>
#include <inttypes.h>
using namespace std;
int main()
{
	long long n;
	long long p;
	ifstream myfile("frac.in");
	myfile >> n >> p;
	myfile.close();
	long long h = 2;
	long nr = 0;
	int diviz[100];
	while (n != 1) 
	{
		bool ok = true;
		while (n % h==0)
		{
			ok = false;
			n = n/h;
		}
		if (!ok) { nr++; diviz[nr-1]=h;}
		h++;
	}
	long long numere = 1;
	while (p>0) 
	{
		bool ok = true;
		for (int i=0;i<nr;i++) if (numere % diviz[i] == 0) { ok = false; break;}
		if (ok) p--;
		numere++;
	}
	ofstream myfile2("frac.out");
	myfile2 << numere-1;
	myfile2.close();
	return 0;
}