#include <stdio.
h>
#include <math.h>//as i need to use powers but getting power with loop is hard
so i used this library
// i watched some videos of code with harry for get some extra knowledge
// there i found using function in video no. 19 or 20. so i used it here as i
found it useful here
// i tried to use nested loops in 4th query but the programm was crashing
// so i used functions to split the task
int a1;
// this setbit function count the number of 1 in input number
int setbit(int num1) {
int a1 = 0;
while (num1 > 0) {
if (num1 % 2 == 1) {a1++;}
num1 /= 2;}
return a1;
}
int main(){
int k,q,a,b,c,d,e,value;
int n=1,m=0,m1=0,l=0,p=0,g=0,b1=0;
double king=pow(10,12);
int x1=pow(10,12);
scanf("%d",&q);//it will take no. of queries
for(int i=0;i<q;i++){
label:
scanf("%d",&k);//the input which decide the query
// for first query
if(k==1){
scanf("%d%d%d",&a,&b,&c);// taking inputs
//using goto statement to retake the input if the given input get beyond the
constrainsts
if((a>10000)||(a<(-10000))){goto label;}
else if((b>10000)||(b<(-10000))){goto label;}
else if((c>10000)||(c<(-10000))){goto label;}
while((a>0)){
value=(a*(l*l)+(b*l)+c);
if(value==1){ printf("0\n"); break;}
else if(value==2){goto this;}
else{
for(g=2;g<value;g++){
if((value%g)==0){b1=1; break;}
else if(((value%g)!=0)&&(g==(value-1))){b1=0; break;}}}
if(b1==0){this:l=l+1;}
else if(b1==1){ printf("%d\n",l); break;}}}
//for 2nd query
if(k==2){
scanf("%d%d",&a,&b);
if((a<0)||(a>king)){goto label;}
else if((b<0)||(b>king)){goto label;}
while(q>0){
d=(n*(n+1))/2;
n=n+1;
if(d>b){break;}
else if((d>=(a))&&(d<=(b)))
{m=m+1;}}
printf("%d\n",m);}
//For 3rd query
if(k==3){
scanf("%d%d",&a,&b);
if((a<0)||(a>king)){goto label;}
else if((b<0)||(b>king)){goto label;}
for(int h=a;h<=b;h++){
if(h%2==0){m1=m1+1;}
else if(h%3==0){m1=m1+1;}
else if(h%5==0){m1=m1+1;}}
printf("%d\n",m1);}
//for 4th query
if(k==4){ scanf("%d%d",&a,&b);
if((a<0)||(a>king)){goto label;}
else if((b<0)||(b>king)){goto label;}
int a2=a,a3=a;
/* a2 and a3 represent max set bit and min set ,we intialize them to set bit of
the 1st number then we are checking with respect to setbit of a */
int a4=setbit(a);
int a5=setbit(a);
// a loop going on to check the condition
for(int y=(a+1);y<=b;y++){
int a6=setbit(y);
if(a6<a4){
// if the setbit count of y < setbit count of a then our lowest set bit
number will be y
a2=y;
a4=a6;//now we are checking with respect to this a4 as it became
the lowest
}
if(a6>a5){
// if the setbit count of y > setbit count of a then our largest set
bit number will be y
a3=y;
a5=a6;//now we are checking with respect to this a5 as it became
the largest
}
}
printf("%d %d\n",a2,a3);}
}return 0;
}