Author Topic: Formula for getting prime number?  (Read 18150 times)

0 Members and 1 Guest are viewing this topic.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Formula for getting prime number?
« Reply #15 on: January 09, 2011, 06:50:49 pm »
for those chrome users who cannot read willrandship's post.

Code: [Select]
Arrange your numbers in a matrix. The width determines the numbers you can eliminate.
Here's the basic concept. The width is a multiple of several prime numbers. If you multiply 3,5,and 7
together you get 105. In the 105 columns, you can eliminate every 3rd starting at 3, every 5th starting
 at 5, and every 7th starting at 7. You don't need to put in two, since you can simply eliminate every
other going down each column (-210 instead of -105)

Example using 3*5 (15)

0   1  2  3  4  5 6  7   8  9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

    1   2     4          7  8          11     13 14
    16 17     19         22 23         26     28 29
    31 32     34         37 38         41     43 44
    46 47     49         52 53         56     58 59

The more primes you multiply in (nonprimes are useless, eliminate no more rows) the more you can eliminate! yay!
Now for checkerboarding for multiples of 2:

    1                        7             11     13 
        17     19             23                     29
    31                     37             41     43
        47     49             53                     59

True, you eliminate two, but who cares? You don't lose any primes.

By the way, doing this exactly this way with 105 (0-104) give you 31.428% remaining, whereas 3 gives 33.333% It's exponentially less effective, but still waaay better than just -2.


Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Formula for getting prime number?
« Reply #16 on: January 09, 2011, 06:52:38 pm »
I put it in a spoiler so It wouldn't take up the whole page, in the code for the monospace for laying out the matrices.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Formula for getting prime number?
« Reply #17 on: January 09, 2011, 06:59:22 pm »
I put it in a spoiler so It wouldn't take up the whole page, in the code for the monospace for laying out the matrices.

code automatically has a scrollbar for that reason. if you put code inside a spoiler, for chrome users, it's virtually unreadable. here is a screenshot.
« Last Edit: January 09, 2011, 06:59:33 pm by nemo »


Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Formula for getting prime number?
« Reply #18 on: January 09, 2011, 07:04:05 pm »
* willrandship shudders

Well, I've used chrome with no real complaints, firefox just has too many plugins to pass up :P

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Formula for getting prime number?
« Reply #19 on: January 09, 2011, 07:51:00 pm »
What I don't understand is why anyone would need to use a sieve methods to find primes for a math class. If the assignment is to generate a list of primes, then there are plenty of lists already available online. If the assignment simply requires prime numbers, then a much more efficient primality test would be applicable
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Formula for getting prime number?
« Reply #20 on: January 09, 2011, 08:00:00 pm »
Oh, @Graphmastur,

I'm not saying you do it for all prime numbers, just a few. Then, you can simply take the remaining rows and add by the matrix width (x2 if you use an odd number)

It's only a gain of roughly 2% over simply adding by 4,2,then 4, then 2, then 4 through two columns arranged by 3 on Trial factoring, though :P

as in
1,2,3
4,5,6
7,8,9
« Last Edit: January 09, 2011, 08:04:10 pm by willrandship »

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Formula for getting prime number?
« Reply #21 on: January 30, 2011, 05:44:59 pm »
Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )
No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.

There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem
« Last Edit: January 30, 2011, 05:45:18 pm by Galandros »
Hobbing in calculator projects.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Formula for getting prime number?
« Reply #22 on: January 30, 2011, 06:07:52 pm »
There is nothing that says it can or cannot be true.  It would kinda fit into the category of P=NP, though. e.g., you can prove S times T equals a number, but finding S and T from that number would be a lot harder.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Formula for getting prime number?
« Reply #23 on: January 30, 2011, 06:16:25 pm »
There is nothing that says it can or cannot be true.  It would kinda fit into the category of P=NP, though. e.g., you can prove S times T equals a number, but finding S and T from that number would be a lot harder.
Yep, I think from what I read it falls on that category.
But almost everyone that works on the area admits that there is not such formula or even it can not exist.

There is the possibility some undiscovered area of Mathematics bring some solution to the problem of getting the primes sequence without going by number testing. Better keep an open spirit about it until we prove otherwise.
Hobbing in calculator projects.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Formula for getting prime number?
« Reply #24 on: January 31, 2011, 08:56:16 am »
Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )
No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.

There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem

Wait a minute... I can code a program that gets all prime numbers in a second.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Formula for getting prime number?
« Reply #25 on: January 31, 2011, 09:24:10 am »
Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )
No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.

There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem

Wait a minute... I can code a program that gets all prime numbers in a second.
For RSA we are talking of numbers with hundreds of decimal digits.
Hobbing in calculator projects.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Formula for getting prime number?
« Reply #26 on: January 31, 2011, 09:27:14 am »
Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )
No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.

There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem

Wait a minute... I can code a program that gets all prime numbers in a second.
For RSA we are talking of numbers with hundreds of decimal digits.

decimal! I thought only integers would take part of such function.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Formula for getting prime number?
« Reply #27 on: January 31, 2011, 09:42:05 am »
Does it exist, if it does, can you tell me?(I need it to do mah APCS Homework D: )
No, there isn't any (known) formula to get the sequence of primes. But I don't know if it was proven mathematically that there is not such formula.
The difficulty to crack RSA depends on being hard to find primes and the interest on primes comes also from this.

There are formulas that give asymptotically the average of number of primes in an interval or probability of a random number being prime. See more in:
http://en.wikipedia.org/wiki/Prime_number_theorem

Wait a minute... I can code a program that gets all prime numbers in a second.
For RSA we are talking of numbers with hundreds of decimal digits.

decimal! I thought only integers would take part of such function.
The number of decimal digits representation of the integer. It is true that it is always integer in this sort of things. Don't confuse "decimal type" with its "decimal representation".
The RSA public key is 1024-bits to 2048-bits in current days. In general, people understand more the quantities when you mention it in decimal than in binary bits.
You barely can imagine the monstrosity of the prime factors...
« Last Edit: January 31, 2011, 09:46:16 am by Galandros »
Hobbing in calculator projects.