Click here to Skip to main content
15,885,743 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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.

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.
 
Share this answer
 
Comments
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
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900