14,333,875 members
Rate this:
See more:
Could you please tell me the logic of printing a prime gap series within a given range i.e. 1 1 2 2 4 2 6....?

What I have tried:

```int T,N,flag=0,i,j;
Scanner scan = new Scanner (System.in);
T = scan.nextInt();
N = scan.nextInt();
for(i=T;i <= N; i++)
{
for(j=2;j```
Posted
Updated 9-Oct-19 12:19pm
phil.o 9-Oct-19 5:44am

The code you have provided is incomplete. Please edit your question and show us the actual code you have so far. Because, as is, this just seems like a "write down for me the part of my homework that I did not try to do myself" game. It's not a fun game for us, and it's a dangerous game for you if you are serious about learning development.
Richard MacCutchan 9-Oct-19 5:45am

That is a mathematics question (and far from clear), not programming. Google will find you lots of white papers on prime numbers.

Rate this:

## Solution 1

Quote:
Could you please tell me the logic of printing a prime gap series within a given range
Naive approach: find the sequence of prime numbers 'in the given range' and print the differences between the consecutive ones.
Richard MacCutchan 9-Oct-19 7:33am

Very clever.
CPallini 9-Oct-19 7:37am

Well, it was hard, but eventually I found it! :-D
Rate this:

## Solution 2

Quote:
Could you please tell me the logic of printing a prime gap series within a given range

Prime is prime numbers. You need to find the list of prime numbers between the 2 given numbers. Aka 000 3 5 7 11 13 17 19 ...
Gap is the difference between 2 concecutive prime numbers in the list
Gap between 3 and 5 is 2
Gap between 5 and 7 is 2
Gap between 7 and 11 is 4
Gap between 11 and 13 is 2