TNQT Digital 2 Coding Question

By using this √n/6 complexity method u get full marks??

Tell us …how to implement that sab ye hi kah rhe h ki pattern h ya I see there is a pattern but how will u implement that… Pls explain.

1 Like

Show me the code…

1 Like

here is a better approach according to me.
step 1.store all prime number from l to r in vector vec
step 2.lets suppose its size is len
step 3.
for(int i=0;i<len-1;i++)
{
for(int j=i+1;j<len;j++)
{
if(vec[j]-vec[i]==6)
{
cout<<vec[i]<<vec[j]<<endl;
break;
}
else if(vec[j]-vec[i]>6)
break;
}
//control reaches here if break is reached.
}

Same here, I also get 6/7 test case.

I also used the Sieve method for the range of 10^7 and passed all test cases in java.
I think there is compiler issue with other languages because i don’t know anyone who has solved this in any other language except java.

1 Like

How did you store all the prime numbers from L to R?
What algorithm?

Same here afaik…
// 20 char

What was your test centre?
// 20 char

Mene nhi diya NQT…

I have tried that method too and you’ll get TLE.

Just click Run button on bottom left, after taking m and n I modified m=2 and n=10e9.
It showed me 0/7 Test cases passed and showed me output for 4 40 public test case, Expected output and my output

Well I passed all 7 Testcases using C++, there isn’t any compiler issue as people are saying.

1 Like

Yeah, there was no compiler problem. Can you tell us the algorithm you used to solve it?

Already told above my friend.

simple traversal and check

  1. Check all prime pairs from 5 with distance of six… Like 5,11,17,23… There will be some point where there will be no more sexy primes.
  2. Repeat above with starting from 7.
  3. Add count no of pairs from step 1 and 2 from 0 till B… There will be some point when the count would no longer increase.
  4. Add count no of pairs from step 1 and 2 from 0 till A-1…
  5. Subtract Step 3 - step 4

this gave TLE to everyone!

1 Like

This 6n+1 or 6n-1 thing is not a concrete logic. Sieve was the right approach to the problem. People who got 7 out of 7 cases passed using sieve were able to do it because the test cases in TCS digital never crosses the limit 10^7.

1 Like