Pagini recente » Cod sursa (job #39845) | Cod sursa (job #1267110) | Cod sursa (job #1101974) | Cod sursa (job #3175067) | Cod sursa (job #252044)
Cod sursa(job #252044)
#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;
}