The Student Room Group

Pythagorean triplets.

Got it. @Zacken could you close this please

Question was:

There is exactly one Pythagorean triplet for which a+b+c=1000a + b + c = 1000
Find the product of abcabc
(edited 8 years ago)
Oh ok nm
Reply 2
Original post by Bobjim12
Oh ok nm


Feel free to share your solution:biggrin:
Original post by edothero
Feel free to share your solution:biggrin:


Oh no, i wasn't really on a solution, i wasn't too sure what you were looking for so i was trying to clarify it, but i guess it doesn't matter anymore XD
Reply 4
Original post by Bobjim12
Oh no, i wasn't really on a solution, i wasn't too sure what you were looking for so i was trying to clarify it, but i guess it doesn't matter anymore XD


Lmao yeah xD the solution is
a = 200
b = 375
c = 425

a^2 + b^2 = c^2
and
a+b+c = 1000
:biggrin:
Original post by edothero
Lmao yeah xD the solution is
a = 200
b = 375
c = 425

a^2 + b^2 = c^2
and
a+b+c = 1000
:biggrin:


How did you get it? I like seeing code!!
Reply 6
Original post by edothero
Got it. @Zacken could you close this please


I'll leave it open for the moment - looks like some people are interested in it. :biggrin:
Original post by Zacken
I'll leave it open for the moment - looks like some people are interested in it. :biggrin:


heeeeeeeeey, i'm just curious :frown:
Reply 8
Original post by Zacken
I'll leave it open for the moment - looks like some people are interested in it. :biggrin:


That's fine, thank you anyway :biggrin:.


Original post by Bobjim12
How did you get it? I like seeing code!!


Here's the code: I used Java.public class Ptrips {

public static void main(String[] args) {

int a = 0;
int b = 0;
int c = 0;
int n = 1000;
boolean solution = false;

for(a = 1; a < n; a++){
for(b = a; b < n; b++) {
c = n - a - b;


if ((a*a) + (b*b) == (c*c)) {
solution = true;
break;
}
}
if(solution){
System.out.println(a + ", " + b + " and " + c);
break;
}
}
}
(edited 8 years ago)
Original post by edothero
Thanks fine, thank you anyway :biggrin:.




Here's the code: I used Java.public class Ptrips {

public static void main(String[] args) {

int a = 0;
int b = 0;
int c = 0;
int n = 1000;
solution = false;

for(a = 1; a < n; a++){
for(b = a; b < n; b++) {
c = n - a - b;


if ((a*a) + (b*b) == (c*c)) {
solution = true;
break;
}
}
if(found){
System.out.println(a + ", " + b + ", " + c);
break;
}
}
}


Ok, i did misunderstand what you were asking,

I'm not sure if it would work but instead of having the c = n- a -b statement you could combine that with the if statement, if you want it to be slightly more efficient but if it works you probably don't want to bother!

how do indices work in Java? does 2**2 = 4?
(edited 8 years ago)
Reply 10
Original post by Bobjim12
Ok, i did misunderstand what you were asking,

I'm not sure if it would work but instead of having the c = n- a -b statement you could combine that with the if statement, if you want it to be slightly more efficient but if it works you probably don't want to bother!

how do indices work in Java? does 2**2 = 4?


I think if I combine it with the if statement then I would need two of them! One for a2+b2=c2a^{2}+b^{2}=c^{2} and one for c=nabc = n - a - b

The only other thing I can think of atm isif((c = n - a - b) && (a*a + b*b == c*c)) {
solution = true;
break;
}

Which would definitely be more efficient, good spot!


As for the indices thing, I'm not quite sure you know :rofl:
Give me a sec.

Aha, got it; unlike languages like Python you can't do a**b for aba^{b}
You need to use Math.pow(n, n1)Which would return nn1n^{n_{1}}

Though it would return it as a double (i.e)System.out.println(Math.pow(2, 2));would return 4.0
(edited 8 years ago)
Original post by edothero
I think if I combine it with the if statement then I would need two of them! One for a2+b2=c2a^{2}+b^{2}=c^{2} and one for c=nabc = n - a - b

The only other thing I can think of atm isif((c = n - a - b) && (a*a + b*b == c*c)) {
solution = true;
break;
}


That.should work, if i am in the right frame of mind right now!
Reply 12
Original post by Bobjim12


how do indices work in Java? does 2**2 = 4?


I think the usual thing is Math.Pow(a, b).
Original post by Zacken
I think the usual thing is Math.Pow(a, b).


Hmm, that is interesting.

you could then just do Math.Pow(n-a-b, 2)

Assuming i am getting the args right.
Reply 14
Original post by Bobjim12
That.should work, if i am in the right frame of mind right now!


Check the post again, I've made a few edits :biggrin:
Zacken has beat me to it though, the guys unstoppable :biggrin:
Reply 15
Original post by Bobjim12
Hmm, that is interesting.

you could then just do Math.Pow(n-a-b, 2)

Assuming i am getting the args right.


That would be (n-a-b)^2, yeah.
Original post by Zacken
That would be (n-a-b)^2, yeah.


Slightly off topic but do you know if you do much using programming in the Cambridge maths course?
Splendid, well, this was fun haha!
Reply 18
Original post by Student403
Slightly off topic but do you know if you do much using programming in the Cambridge maths course?


Very little in terms of using MatLab for a lengthy computation project in second and third years called "Catam", details should be available online, I think.
Original post by Zacken
Very little in terms of using MatLab for a lengthy computation project in second and third years called "Catam", details should be available online, I think.


Cheers :smile: Good thread, this!

Quick Reply

Latest