![]() |
![]() |
#1 |
Sep 2002
3C16 Posts |
![]()
I need a fast function which determines whether 3 numbers are relatively prime. I'm thinking of doing 3 GCF's, but that seems slow.
|
![]() |
![]() |
![]() |
#2 |
"Richard B. Woods"
Aug 2002
Wisconsin USA
22×3×641 Posts |
![]()
Just 2 GCDs, right? gcd ( gcd ( A, B ), C )
I've seen library GCDs that took more than two arguments, but the question would be whether anyone's coded a really fast one. [Edit: Oh, swiss! I just realized that I got it backward, but find that hyh1048576 has already pointed that out, so I can't save face by sneaking in a silent edit. Ya know, as ya get older yer subconscious gets wiser but also gets slower.] |
![]() |
![]() |
![]() |
#3 | |
Jun 2003
26 Posts |
![]() Quote:
If gcd(A,B)>1, they are not relatively primes. So when A,B,C are relatively primes, gcd(A,B)=1, so gcd ( gcd ( A, B ), C )=gcd(1,C) must be equal to 1 ![]() My method is A,B,C are relatively primes iff gcd(A,B) and gcd(AB,C) are both equal to 1 :) |
|
![]() |
![]() |
![]() |
#4 |
Sep 2002
3C16 Posts |
![]()
Thanks for your help, I'll see how it goes.
|
![]() |
![]() |
![]() |
#5 |
∂2ω=0
Sep 2002
República de California
265268 Posts |
![]()
There is no reason one needs to restrict the GCD to 2 inputs, i.e. N numbers x_1, ..., x_N are relatively prime iff GCD(x_1, ..., x_N) = 1. Of course if the GCD implementation one is using only allows for 2 inputs, one would have to do N-1 pairwise GCDs, but that has the advantage that if any one of these gives a result > 1, one can stop right there.
|
![]() |
![]() |
![]() |
#6 |
Cranksta Rap Ayatollah
Jul 2003
12018 Posts |
![]()
it seems to me that there should be some way to short circuit this to just look for relatively prime or not, instead of finding out the greatest common divisor.
doing GCD's seems like factoring a number to see if it is prime .. Any thoughts? |
![]() |
![]() |
![]() |
#7 |
Feb 2003
2×3×29 Posts |
![]()
Ernst -
Why don't we need N choose 2 gcd's. Or are we not talking about pairwise relatively prime numbers? |
![]() |
![]() |
![]() |
#8 | |||
∂2ω=0
Sep 2002
República de California
2D5616 Posts |
![]() Quote:
Quote:
Quote:
The Gnu MP package has fast GCD algorithms of various kinds (and both regular and "extended" GCDs - the latter are handy for finding modular inverses). |
|||
![]() |
![]() |
![]() |
#9 |
Cranksta Rap Ayatollah
Jul 2003
641 Posts |
![]()
Forest. Trees.
I'm not talking about the algorithmic details, I know that finding the GCD and factoring are very different, I meant that finding the GCD in the context of testing integers to be RP is akin to factoring a number to prove primality. The definition of a prime number is a number that has only itself and 1 as factors, but that doesn't mean you have to check every number between 1 and p and see if it is a factor, or even factor p to find out it is prime .. what I'm saying is that if you find GCD(36,45) you get 9, but if you just wanted to know if 36 and 45 are relatively prime, getting 9 is extraneous information .. all you need is one bit of information,where RP(36,45) = false Perhaps the algorithms for GCD are so fast that this isn't a practical issue, but it still might provide some interest. (Finding a polynomial-time primality proving algorithm is of interest, despite the fact that there are more optimized algorithms out there, again, I'm speaking conceptually) |
![]() |
![]() |
![]() |
#10 |
Feb 2003
2×3×29 Posts |
![]()
IIRC the Euclidean Algorithm for computing GCD is O(n*lg n) in the size of the input, so you are not likely to get much faster than that.
|
![]() |
![]() |
![]() |
#11 | ||
"Richard B. Woods"
Aug 2002
Wisconsin USA
22×3×641 Posts |
![]() Quote:
The situation for relatively prime numbers is not analogous. For a given number, the property of being relatively prime to another number is a less fundamental property than the property of being prime itself. So AFAIK no one has found any method of distinguishing relatively prime numbers from relatively nonprime numbers that is simpler than calculating the GCD and comparing that to 1. Quote:
|
||
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
(M48) NEW MERSENNE PRIME! LARGEST PRIME NUMBER DISCOVERED! | dabaichi | News | 571 | 2020-10-26 11:02 |
Twin Prime Days, Prime Day Clusters | cuBerBruce | Puzzles | 3 | 2014-12-01 18:15 |
disk died, prime work lost forever? where to put prime? on SSD or HDD? | emily | PrimeNet | 3 | 2013-03-01 05:49 |
Prime Cullen Prime, Rest in Peace | hhh | Prime Cullen Prime | 4 | 2007-09-21 16:34 |
The 40th known Mersenne prime, 220996011-1 is not PRIME! | illman-q | Miscellaneous Math | 33 | 2004-09-19 05:02 |