Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.math.*;
- public class BigCell{
- //VB for variable so it doesn't interfere with simple getter names
- private BigInteger iVB;
- private BigInteger jVB;
- private BigInteger aVB;
- private BigInteger bVB;
- private BigInteger cVB;
- private BigInteger dVB;
- private BigInteger eVB;
- private BigInteger fVB;
- private BigInteger nVB;
- private BigInteger xVB;
- private BigInteger tVB;
- private BigInteger xplusnVB;
- private BigInteger dplusnVB;
- private BigInteger xplusnsquaredVB;
- private BigInteger dplusnsquaredVB;
- private BigInteger uVB;
- private BigInteger bignVB;
- private BigInteger naVB;
- private boolean oddxplusnsquaredVB;
- private String descriptionV;
- public BigCell(String aSend, String bSend){
- this(new BigInteger(aSend), new BigInteger(bSend));
- }
- public BigCell(String aSend, String bSend, String fSend){
- this(new BigInteger(aSend), new BigInteger(bSend), new BigInteger(fSend));
- }
- public BigCell(BigInteger aSend, BigInteger bSend){
- aVB = aSend;
- bVB = bSend;
- cVB = aVB.multiply(bVB);
- dVB = sqrt(cVB);
- eVB = cVB.subtract(dVB.multiply(dVB));
- fVB = eVB.subtract((dVB.multiply(BigInteger.valueOf(2))).add(BigInteger.valueOf(1)));
- nVB = ((aVB.add(bVB)).divide(BigInteger.valueOf(2))).subtract(dVB);
- xVB = dVB.subtract(aVB);
- tVB = BigInteger.valueOf(0);
- if((eVB.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- tVB = (xVB.add(BigInteger.valueOf(2))).divide(BigInteger.valueOf(2));
- } else {
- tVB = (xVB.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
- }
- iVB = nVB.add(dVB);
- jVB = bVB.subtract(iVB);
- xplusnVB = xVB.add(nVB);
- dplusnVB = dVB.add(nVB);
- xplusnsquaredVB = xplusnVB.multiply(xplusnVB);
- dplusnsquaredVB = dplusnVB.multiply(dplusnVB);
- uVB = BigInteger.valueOf(0);
- oddxplusnsquaredVB = true;
- if((xplusnsquaredVB.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- oddxplusnsquaredVB = false;
- uVB = xplusnVB.divide(BigInteger.valueOf(2));
- } else {
- uVB = (xplusnVB.subtract(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
- }
- bignVB = ((cVB.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2))).subtract(dVB);
- descriptionV = "("+eVB+","+nVB+","+tVB+") = {"+eVB+":"+nVB+":"+dVB+":"+xVB+":"+aVB+":"+bVB+"}, f="+fVB+", c="+cVB+", u="+uVB+", i="+iVB+", j="+jVB;
- }
- public BigCell(BigInteger aSend, BigInteger bSend, BigInteger fSend){
- aVB = aSend;
- bVB = bSend;
- cVB = aVB.multiply(bVB);
- dVB = (sqrt(cVB)).add(BigInteger.valueOf(1));
- eVB = fSend;
- fVB = eVB.add((dVB.multiply(BigInteger.valueOf(2))).subtract(BigInteger.valueOf(1)));
- nVB = ((aVB.add(bVB)).divide(BigInteger.valueOf(2))).subtract(dVB);
- xVB = dVB.subtract(aVB);
- tVB = BigInteger.valueOf(0);
- if((eVB.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- tVB = (xVB.add(BigInteger.valueOf(2))).divide(BigInteger.valueOf(2));
- } else {
- tVB = (xVB.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
- }
- iVB = nVB.add(dVB);
- jVB = bVB.subtract(iVB);
- xplusnVB = xVB.add(nVB);
- dplusnVB = dVB.add(nVB);
- xplusnsquaredVB = xplusnVB.multiply(xplusnVB);
- dplusnsquaredVB = dplusnVB.multiply(dplusnVB);
- uVB = BigInteger.valueOf(0);
- oddxplusnsquaredVB = true;
- if((xplusnsquaredVB.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- oddxplusnsquaredVB = false;
- uVB = xplusnVB.divide(BigInteger.valueOf(2));
- } else {
- uVB = (xplusnVB.subtract(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
- }
- bignVB = ((cVB.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2))).subtract(dVB);
- descriptionV = "("+eVB+","+nVB+","+tVB+") = {"+eVB+":"+nVB+":"+dVB+":"+xVB+":"+aVB+":"+bVB+"}, f="+fVB+", c="+cVB+", u="+uVB+", i="+iVB+", j="+jVB;
- }
- public static BigInteger sqrt(BigInteger x) {
- if(x.equals(BigInteger.ZERO)){
- return BigInteger.ZERO;
- }
- boolean negative = false;
- if(x.compareTo(BigInteger.valueOf(0)) == -1){
- negative = true;
- x = x.multiply(BigInteger.valueOf(-1));
- }
- BigInteger div = BigInteger.ZERO.setBit(x.bitLength()/2);
- BigInteger div2 = div;
- BigInteger returnvalue = BigInteger.valueOf(0);
- // Loop until we hit the same value twice in a row, or wind
- // up alternating.
- for(;;) {
- BigInteger y = div.add(x.divide(div)).shiftRight(1);
- if (y.equals(div) || y.equals(div2)){
- returnvalue = y;
- break;
- }
- div2 = div;
- div = y;
- }
- BigInteger testsquare = returnvalue.multiply(returnvalue);
- BigInteger testp1square = (returnvalue.add(BigInteger.valueOf(1))).multiply(returnvalue.add(BigInteger.valueOf(1)));
- if((testsquare.equals(x)) || (((testsquare.compareTo(x)) == -1) && ((testp1square.compareTo(x)) == 1))){
- if(negative){
- returnvalue = returnvalue.multiply(BigInteger.valueOf(-1)); //hacky fix to very specific problem
- }
- return returnvalue;
- } else {
- return returnvalue.subtract(BigInteger.valueOf(1));
- }
- }
- public BigInteger a(){
- return aVB;
- }
- public BigInteger b(){
- return bVB;
- }
- public BigInteger c(){
- return cVB;
- }
- public BigInteger d(){
- return dVB;
- }
- public BigInteger e(){
- return eVB;
- }
- public BigInteger f(){
- return fVB;
- }
- public BigInteger n(){
- return nVB;
- }
- public BigInteger x(){
- return xVB;
- }
- public BigInteger t(){
- return tVB;
- }
- public BigInteger i(){
- return iVB;
- }
- public BigInteger j(){
- return jVB;
- }
- public BigInteger xplusn(){
- return xplusnVB;
- }
- public BigInteger dplusn(){
- return dplusnVB;
- }
- public BigInteger xplusnsquared(){
- return xplusnsquaredVB;
- }
- public BigInteger dplusnsquared(){
- return dplusnsquaredVB;
- }
- public BigInteger u(){
- return uVB;
- }
- public BigInteger bign(){
- return bignVB;
- }
- public boolean oddxplusnsquared(){
- return oddxplusnsquaredVB;
- }
- public void print(){
- System.out.println(descriptionV);
- }
- public String description(){
- return descriptionV;
- }
- public boolean isPrime(BigInteger c){
- if(c.equals(BigInteger.valueOf(1)) || c.mod(BigInteger.valueOf(2)).equals(BigInteger.valueOf(0))){
- return false;
- }
- BigInteger d = sqrt(c);
- BigInteger bign = ((c.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2))).subtract(d);
- BigInteger n = BigInteger.valueOf(1);
- if((bign.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- n = n.add(BigInteger.valueOf(1));
- }
- while(n.compareTo(bign) == -1){
- BigInteger x = (sqrt(((d.add(n)).multiply(d.add(n))).subtract(c))).subtract(n);
- BigInteger a = d.subtract(x);
- BigInteger b = a.add((x.multiply(BigInteger.valueOf(2))).add(n.multiply(BigInteger.valueOf(2))));
- BigInteger testc = a.multiply(b);
- if(testc.equals(c)){
- return false;
- }
- n = n.add(BigInteger.valueOf(2));
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment