Last active
June 17, 2018 07:32
-
-
Save JoshCheek/1b9bf9ac3da6118375b635777958df46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static java.lang.Math.sqrt; | |
import java.math.BigInteger; // https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html | |
public class PE100 { | |
static BigInteger zero = new BigInteger("0"); | |
static BigInteger one = new BigInteger("1"); | |
static BigInteger two = new BigInteger("2"); | |
static BigInteger four = new BigInteger("4"); | |
static BigInteger eight = new BigInteger("8"); | |
static BigInteger sixteen = new BigInteger("16"); | |
public static void main(String[] args) { | |
BigInteger rRoot = new BigInteger("292893218813"); | |
// BigInteger rRoot = new BigInteger("7"); | |
BigInteger s = rRoot.multiply(rRoot).multiply(eight).add(one); | |
BigInteger sRoot = rRoot; // there/s not a square root function for this type, so start from r, even though we know it's a long way off | |
BigInteger sSquare = sRoot.multiply(sRoot); | |
while(true) { | |
for(int i=0; i < 10000000; ++i) { | |
int cmp = sSquare.compareTo(s); | |
if(cmp<0) { | |
sRoot = sRoot.add(two); | |
sSquare = sRoot.multiply(four).subtract(four).add(sSquare); // sSquare += 4*sRoot-4 | |
} else { | |
if(cmp == 0) { | |
System.out.println("WINNING!"); | |
show(rRoot, sRoot); | |
return; | |
} | |
rRoot = rRoot.add(one); | |
s = rRoot.multiply(sixteen).subtract(eight).add(s); // s += 16*rRoot-8 | |
} | |
} | |
show(rRoot, sRoot); | |
} | |
} | |
public static void show(BigInteger r, BigInteger sRoot) { | |
// b = (2*r + 1 + sRoot)/2; | |
BigInteger b = r.multiply(two).add(one).add(sRoot).divide(two); | |
System.out.printf( | |
"b: %s, r: %s, a: %s\n", | |
b.toString(), r.toString(), b.add(r).toString() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment