Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Java 8

int count=0;

for(int i=l;i<=r;i++)
{
double kk=(double)i;
int k=(int) Math.sqrt(kk);
for(int x=0;x<=k+1;x++)
{
for(int y=x;y<=k+1;y++)
{
for(int g=2;g<=3;g++)
for(int h=g;h<=3;h++)
if((Math.pow(x,g)+Math.pow(y,h))==i)
{
System.out.println(x+" "+y);
count++;
}

}
}

return count;

Java 7

int count=0;

ArrayList arr=new ArrayList();


int i;

if(l>=0 && r>=l && r<=5000000)


{
for(i=l;i<=r;i++)
arr.add(i);

double kk=(double)i;
int k=(int) Math.sqrt(kk);
for(int x=0;x<=k;x++)
{
for(int y=x;y<=k;y++)
{

for(int g=2;g<=7;g++)
for(int h=2;h<=7;h++)
{
int sum=(int)(Math.pow(x,g)+Math.pow(y,h));
if(arr.contains(sum))
{
int ii=arr.indexOf(sum);
arr.remove(ii);
// System.out.println(x+" "+y);
count++;
}
}
}
}

}
return count;

________________

else if(l>=0 && r>=l && r>50000 && r<=500000)


{
for(int x=600;x<=k;x++)
{
for(int y=x;y<=k;y++)
{

for(int g=2;g<=7;g++)
for(int h=2;h<=7;h++)
{
int sum=(int)(Math.pow(x,g)+Math.pow(y,h));
if(arr.contains(sum))
{
int ii=arr.indexOf(sum);
arr.remove(ii);
count++;
}
}
}
}
}
else if(l>=0 && r>=l && r>500000 && r<=5000000)
{

_________________

static String mergeStrings(String a, String b) {

int alen=a.length();
int blen=b.length();
char aa[]=a.toCharArray();
char bb[]=b.toCharArray();
char[] result=new char[alen+blen];
int i=0,j=0,k=0;
String op=null;
if((alen>25000 && blen>25000) || (alen<1 && blen<1))
{
System.exit(1);
}
else if(alen>=1 && alen<=25000 && blen>=1 && blen<=25000)
{
while(i<alen && j<blen)
{
result[k]=aa[i];i++;k++;
result[k]=bb[j];j++;k++;
}

while(alen>blen && k<(alen+blen))


{
result[k]=aa[i];i++;k++;
}
while(blen>alen && k<(alen+blen))
{
result[k]=bb[i];j++;k++;
}
op=String.valueOf(result);
}
else if(alen<1 && blen>=1 && blen<=25000)
{
op=b;
}
else if (alen>=1 && alen<=25000 && blen<1)
{
op=a;
}
else if(alen>25000 && blen>=1 && blen<=25000)
{
op=b;
}
else if (alen>=1 && alen<=25000 && blen<25000)
{
op=a;
}
return op;
}

You might also like