Cod sursa(job #252044)

Utilizator mariusandreiMarius Lucian Andrei mariusandrei Data 3 februarie 2009 20:27:42
Problema Divizori Primi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream>
using namespace std;
const int N=1000001;
int main()
{
	ifstream in("divizori.in");
	ofstream out("divizori.out");
	int t,v[15],x=0,max;
	in>>t;
	for(int i=1;i<=t+t;i+=2)
	{
		in>>v[i]>>v[i+1];
		if(x==0)
		{
			max=v[i];
			x=1;
		}
		else if(max<v[i])
			max=v[i];
	}
	char c[N]={0};
	c[1]=1;
	for(int i=2; i*i<=max; ++i)
		if(c[i]==0)
			for(int j=i*i; j<=max; j+=i)
				c[j]=1;
	int nr;
	for(int i=1; i<=t+t; i+=2)
	{
		x=1;
		nr=1;
		for(int j=1;x<=v[i+1]; ++j)
		{
			if(c[j]==0)
			{
				nr*=j;
				++x;
			}
		}
	if(nr<=v[i])	
		out<<nr<<"\n";
	else 
		out<<"0"<<"\n";
	}
	in.close();
	out.close();
	return 0;
}