Hello,
I would like to write a program that detects pairs of primes (p,p') satisfying the form p'-p=2k, where k is a positive integer. I am new to programming, and this is beyond my level of competence.
All help and comments are appreciated.
//Espen
11 replies to this topic
#1
Posted 26 May 2010 - 03:21 AM
|
|
|
#2
Posted 26 May 2010 - 06:42 AM
what are the assumptions regarding the input? Can you assume that you will be given only primes or do you have to check it by yourself? Basically first try to understand what kind of mini-tasks your assignment includes and then think how to implement each. On that note, how would you check whether some number is even? Prime?
#3
Posted 26 May 2010 - 10:41 AM
p' - p = 2k if and only if (p' - p)%2 == 0 if and only if p' and p are both 2 or neither are 2.
#4
Posted 26 May 2010 - 12:08 PM
bobdark said:
what are the assumptions regarding the input? Can you assume that you will be given only primes or do you have to check it by yourself? Basically first try to understand what kind of mini-tasks your assignment includes and then think how to implement each. On that note, how would you check whether some number is even? Prime?
I was thinking of perhaps first generating primes with the sieve of Atkin (or something similar), hence assuming the input to be primes exclusively. Further, it would be necessary to find the difference between all consecutive primes in the sequence. The pairs should be arranged in tables of being twin primes, cousin primes, sexy primes etc. (that is, the difference being 2,4,6...).
I don't know if this is what you meant. Please correct me if it was not.
#5
Posted 03 June 2010 - 11:28 AM
Does anyone have a suggestion on where to start?
#6
Posted 03 June 2010 - 11:38 AM
What is the program supposed to do? Generate pairs of primes? Or given two numbers x and y, determine whether x and y are primes and the result of subtraction between x and y is an even number? It's not clear from what you wrote here.
#7
Posted 03 June 2010 - 12:22 PM
if p' and p are prime number then both of them is odd number. So an odd number subtract an odd number will be a even number. you just generate two primes p and p'.
#8
Posted 03 June 2010 - 12:45 PM
bobdark said:
What is the program supposed to do? Generate pairs of primes? Or given two numbers x and y, determine whether x and y are primes and the result of subtraction between x and y is an even number? It's not clear from what you wrote here.
Excuse me if the first attempt of an explanation was bad, but I do not know how to put it in any other way. The program will be given the sequence of primes up to a certain prime (p1, p2, p3, p4 ... pn that is 2, 3, 5, 7 ... n). Further, it should find the difference between each successive prime (prime n+1 minus prime n, these two primes are what I refer to as a "pair". ex: 5-3=2. 3 and 5 form the pair) and determine how large the difference is. Lastly, it would be preferable if the pairs could be arranged consecutively in separate tables or lists of twin primes, cousin primes etc. Is it clearer, or still impossible to understand?
#9
Posted 03 June 2010 - 12:58 PM
what do you refer to as twin and cousin primes?
#10
Posted 03 June 2010 - 01:01 PM
Twin primes - difference is 2, cousin primes - difference is 4, sexy primes - difference is 6 .... More info on wikipedia, I would guess.
Examples: (3, 5) are twin primes, (7, 11) are cousin primes etc.
Examples: (3, 5) are twin primes, (7, 11) are cousin primes etc.
#11
Posted 03 June 2010 - 01:20 PM
Well, assuming you don't refer to database tables, but to tables displayed in a console, I think I would create a linked list structure where each node would hold a linked list of pairs of primes of a specific relation. Basically, MainList would hold TwinsList, CousinsList, etc. Each node in a list responsible for a relation between two primes, would hold a pair of primes which are related accordingly - for example TwinsList would hold a node for (3,5), another one for (5,7), another for (17,19) etc.
You can easily maintain those lists sorted and if you want tables, you only have to write a printing function that iterates over each list of the main list.
If you're not familiar with linked list, Winged Panther wrote a tutorial on it and presented the whole thing quite nicely - search for it and read it.
Again, this is the way I would do it. Maybe someone here can propose something easier.
You can easily maintain those lists sorted and if you want tables, you only have to write a printing function that iterates over each list of the main list.
If you're not familiar with linked list, Winged Panther wrote a tutorial on it and presented the whole thing quite nicely - search for it and read it.
Again, this is the way I would do it. Maybe someone here can propose something easier.
#12
Posted 03 June 2010 - 01:24 PM
Thank you! I will look into it.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









