Cod sursa(job #368935)

Utilizator cvicentiuCiorbaru Vicentiu Marian cvicentiu Data 26 noiembrie 2009 17:25:40
Problema Frac Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>
using namespace std;
fstream fin ("frac.in",ios::in);
fstream fout("frac.out",ios::out);

long n, p;
bool v[4000001];
void fact(long p){
	long count = 2;
	while (p != 1){
		if (!(p % count)){
			for (long i = count; i <= 4000000; i += count)
				v[i] = true;
			while (!(p % count)){
				p /= count;
			};
		};
		++count;
	};
};


int main(){
	fin >> n >> p;
	fact(n);
	long count = 0;
	for (long i = 1;; ++i){
		if (!v[i]) ++count;
		if (count == p){
			fout<<i;
			return 0;
		};
	};
	
	
};