Results 1 to 11 of 11
 03072013, 02:23 PM #1Member
 Join Date
 Jan 2013
 Posts
 7
 Rep Power
 0
finding a special pythagorean triplet using Euclid's formula
as the title says i'm trying to find a phythagorean triplet that has the sum 1000 (a + b + c = 1000) i wanted to do this using Euclids formula but I keep failingto find the correct values for abc so please help :D
Code:Euclid's formula[1] is a fundamental formula for generating Pythagorean triples given an arbitrary pair of positive integers m and n with m > n. The formula states that the integers a = m^2  n ^2 , b = 2mn , c = m^2 + n ^2 form a Pythagorean triple. The triple generated by Euclid's formula is primitive if and only if m and n are coprime and m − n is odd. If both m and n are odd, then a, b, and c will be even, and so the triple will not be primitive; however, dividing a, b, and c by 2 will yield a primitive triple if m and n are coprime. Every primitive triple (possibly after exchanging a and b) arises from a unique pair of coprime numbers m, n, one of which is even. It follows that there are infinitely many primitive Pythagorean triples.
Java Code:import static java.lang.Math.*; public class Nine { public static void main(String[] arg){ int m = 1,n = 1,r = 1,tempm,tempn,checkifcoprimes,check; double a = 0,b = 0,c = 0,answer = 0; while(answer != 1000){ m++; if(m == 1000){ m = 1; n++; } if(n == 1000 && answer != 1000){ System.out.println("fail"); System.exit(0); } tempm = m; tempn = n; while(r != 0){ r = m % n; m = n; if(r != 0) n = r; } checkifcoprimes = n; m = tempm; n = tempn; r = 1; check = mn; if(checkifcoprimes == 1 && m > n) { if(m%2 != 0 && n != 0){ a = (pow(m,2)  pow(n,2)) / 2; b = (2 * m * n) / 2; c = (pow(m,2) + pow(n,2)) / 2; } else if(check%2 != 0){ a = (pow(m,2)  pow(n,2)); b = (2 * m * n); c = (pow(m,2) + pow(n,2)); } if(a < b && b < c){ answer = a+b+c; if(answer == 1000) System.out.println("found the triplets"); } } } } }
 03072013, 03:59 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
Re: finding a special pythagorean triplet using Euclid's formula
It's just a bit of simple math: if a+b+c == 1000 then m^2n^2 + 2mn + m^2+n^2 == 2m^2 +2mn == 1000, so m(m+n) == 500. Check all divisors of 500 and you're done with it.
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 03072013, 04:06 PM #3Member
 Join Date
 Jan 2013
 Posts
 7
 Rep Power
 0
 03072013, 04:19 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
Re: finding a special pythagorean triplet using Euclid's formula
The only person who got everything done by Friday was Robinson Crusoe.
 03072013, 05:45 PM #5Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 5,248
 Rep Power
 9
Re: finding a special pythagorean triplet using Euclid's formula
On the contrary. The problem is much harder and more of a trial and error situation just using sides a, b, and c. Using Euclid's formula allows a, b, and c to be expressed in terms of m and n and then reduced to a simpler formula.
Regards,
JimLast edited by jim829; 03072013 at 05:54 PM. Reason: bad morning
The Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 03072013, 06:10 PM #6Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 5,248
 Rep Power
 9
Re: finding a special pythagorean triplet using Euclid's formula
Ok, I think I found out what I was trying to say earlier. By definition, a Pythagorean primitive triplet's sides have no common factor. However, unless I am misunderstanding something, you can't find a primitive triple whose sides add up to 1000. But you can reduce Jos' equation by using number theory. Since m(m+n) = 500 and m and n are relatively prime (and one of m,n must be odd, the other even), then m + n must be odd. Since m(m+n) = 500 and m+n is odd, then m must be even because both sides of the equation are divisible by 2. So let m = 2r. r(2r + n) = 250. = 2 * 5 * 5 * 5. Since n is odd 2r + n must be odd so r is divisible by 2. so r = 2s and s(4s + n) = 125. This leads to a trivial solution where m=4s, and s(4s+n) = 5*5*5. (My apologies if this deviates too much from the forum).
Regards,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
 03072013, 06:34 PM #7
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
Re: finding a special pythagorean triplet using Euclid's formula
No need to apologize at all; nowadays programming lacks sometimes obvious math and the most cripple solutions are stamped as final solutions, while a bit of math could've resulted in a much more efficient algorithm; but mathematics seem to be a dirty knowledge, it's better to hack yourself through a problem without a bit of thinking ...
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 03072013, 07:13 PM #8Moderator
 Join Date
 Apr 2009
 Posts
 12,768
 Rep Power
 22
 03102013, 03:36 PM #9Member
 Join Date
 Jan 2013
 Posts
 7
 Rep Power
 0
 03102013, 04:40 PM #10
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
Re: finding a special pythagorean triplet using Euclid's formula
The only person who got everything done by Friday was Robinson Crusoe.
 03102013, 05:43 PM #11Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 5,248
 Rep Power
 9
Re: finding a special pythagorean triplet using Euclid's formula
No I am not saying that at all. Sorry if I misled you. You can find any Pythagorean triplet with Euclids formula just by making certain that m > n (so that m^2  n^2) is > 0.
However, unless, m and n are relatively prime, and one is odd and the other even (i.e. m  n is odd), then you will not have a primitive triplet. And just to ensure we are on the same page, a primitive triplet is one where no two sides have a common divisor > 1.
Unless I made a mistake above, there is no Pythagorean primitive triplet where a, b, and c add up to 1000. However, there is a solution where they add up to 1000 for a nonprimitive triplet (i.e all sides will be divisible by 5).
Regards,
JimThe Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads

Kwadratic formula
By BURNY26 in forum New To JavaReplies: 20Last Post: 03262012, 04:31 PM 
Help: Pythagorean Triples
By mchahal22 in forum New To JavaReplies: 18Last Post: 12262010, 08:49 AM 
changing TF formula
By o.imen in forum LuceneReplies: 0Last Post: 09162010, 01:20 PM 
Formula Builder
By rbs100 in forum Advanced JavaReplies: 1Last Post: 07032009, 06:57 PM 
What is the formula?
By yuchuang in forum New To JavaReplies: 3Last Post: 04302007, 10:00 PM
Bookmarks