This code is for calculating the perfect squares between two given numbers. User can add the interval as well like for how many intervals he want to check the perfect squares. For example if user enter 4, it means there are 4 different intervals and after that he will insert the tow number for interval 1, similarly two numbers for interval 2 and respectively 3 and 4. I just want to reduce the execution time
import java.io.*;
import java.util.*;
class node{
private int a;
private int b;
node(int a, int b){
this.a = a;
this.b = b;
}
int getA(){return a;}
int getB(){return b;}
}
public class Solution {
public static void main(String[] args) {
int size;
Scanner S1 = new Scanner(System.in);
size = S1.nextInt();
node a[] = new node[size];
for(int i = 0; i<a.length; i++){
/*int number = S1.nextInt();
int number2 = S1.nextInt();*/
a[i] = new node(S1.nextInt(), S1.nextInt());
}
int total = 0;
int sqrt = 0;
for(int i = 0; i<a.length; i++){
for(int j = a[i].getA(); j<=a[i].getB(); j++){
sqrt = (int) Math.sqrt(j);
if(sqrt*sqrt == j) {
total++;
}
}
System.out.println(total);
total = 0;
}
}
}