Challenges-arrays-prime vitis

How can i optimize it? one of the test case is showing time limit.

@nirbhayvashisht
Your this part of code is taking time of Order(size)* l,where size is h-l,
and multiplied with no of test Cases,
Your Code takes N*(b-a)*a time.—>(eq1)

Now consider,N=1000, b=100000 and a=100.
Substituting in eq1–>we have roughly 1000*(100000-100)*100 =~10^10 Operations But 10^8 Operations are accepted on Hacker Blocks.
So please try to optimize your logic of finding the Prime.

            for (int i=0;i<size;i++){

            arr[i]=l;
            //System.out.println("arr");
            int temp=arr[i];
            int count =0;

            for (int j=1;j<=temp;j++){
                if (temp%j==0){
                    count++;
                }

Once optimized revert back here.
Thankyou

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.