Deepak and primes II

test case 2,6,7 WA
TEST CASE 1 tle

#include<bits/stdc++.h>
using namespace std;
#define ll long long
void optimised(int arr[],ll n)
{

memset(arr,0,sizeof(arr));
arr[0]=arr[1]=0;
arr[2]=1;
for(ll i=3;i<=n+5;i+=2)
    arr[i]=1;
for(ll i=3;i<=n+5;i+=2)
{

    if(arr[i])
    {

        for(ll j=i*i;j<=n+5;j+=(2*i))
        {

            arr[j]=0;
        }
    }
}

}
void seg(ll a,ll b,int ans[])
{ll n=sqrt(b)+5;

int p[n];

memset(p,0,sizeof§);
optimised(p,n);

for(int i=0;i<=b-a;i++)
    ans[i]=1;

for(ll i=2;i*i<=b;i++)
{
    for(ll j=a;j<=b;j++)
    {

if(p[i]){
if(j==i)
continue;
if(j%i==0)
ans[j-a]=0;

    }
}}
return;

}
int main()
{int t;
cin>>t;
while(t–)
{

    ll a,b;
    cin>>a>>b;
    int ans[b-a+1];

    seg(a,b,ans);

//for(int i=0;i<b-a;i++)
//cout<<ans[i]<<"**";

    for(ll i=0;i<=b-a;i++)
      {//cout<<"88";

        if(ans[i]==1)
    {//cout<<"lll";
      cout<<i+a<<endl;

    }
      }

        cout<<endl;

}

}

Please don’t paste raw code. Paste your code on ide.codigblocks.com and then saving , send the generated link.

As I did not get any respond from your side , I am closing the thread. You can open the thread again whenever you want.

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.