Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Thirteen;
- import java.math.BigInteger;
- public class Thirteen implements Runnable {
- private BigInteger p, q, r;
- public Thirteen(BigInteger p, BigInteger q, BigInteger r) {
- this.p = p;
- this.q = q;
- this.r = r;
- }
- private BigInteger calculatePSquare() {
- return p.pow(2);
- }
- private BigInteger calculate3TimesPQ() {
- return p.multiply(BigInteger.ONE.add(BigInteger.TWO)).multiply(q);
- }
- private BigInteger calculateQSquare() {
- return q.pow(2);
- }
- private BigInteger calculateRSquare() {
- return r.pow(2);
- }
- public boolean calculateEquation() {
- //Equation: p² + 3pq + q² = r²
- if (calculatePSquare().add(calculate3TimesPQ()).add(calculateQSquare()).equals(calculateRSquare())) {
- System.out.println("p: " + p + " q: " + q + " r: " + r);
- }
- return calculatePSquare().add(calculate3TimesPQ()).add(calculateQSquare()).equals(calculateRSquare());
- }
- @Override
- public void run() {
- calculateEquation();
- }
- }
Add Comment
Please, Sign In to add comment