Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.math.*;
- public class everythingbig{
- private static int buffer = 0;
- public static void main(String[] args){
- Scanner scan = new Scanner(System.in);
- System.out.println("a=");
- String ain = scan.nextLine();
- System.out.println("b=");
- String bin = scan.nextLine();
- BigCell cell = new BigCell(ain, bin);
- System.out.println(cell.description());
- System.out.println();
- System.out.println("=========================================");
- System.out.println();
- System.out.println("c = " + cell.c() + doeverything(cell.c()));
- buffer++;
- recursed(cell.d());
- recursee(cell.e());
- }
- public static void recursed(BigInteger d){
- String dstring = "";
- if((d.compareTo(BigInteger.valueOf(0)) == 1) && ((d.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0)))){
- while(!((d.mod(BigInteger.valueOf(4))).equals(0)) && ((d.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0)))){
- dstring += d + " / ";
- d = d.divide(BigInteger.valueOf(2));
- }
- }
- dstring += d;
- for(int i=0; i<buffer; i++){
- System.out.print(" ");
- }
- System.out.print("d = " + dstring);
- if((d.compareTo(BigInteger.valueOf(3))) == 1){
- System.out.println(" ---" + doeverything(d));
- BigInteger d2 = sqrt(d);
- BigInteger e = d.subtract(d2.multiply(d2));
- buffer++;
- recursed(d2);
- recursee(e);
- buffer--;
- } else {
- System.out.println();
- }
- }
- public static void recursee(BigInteger e){
- String estring = "";
- if((e.compareTo(BigInteger.valueOf(0)) == 1) && ((e.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0)))){
- while(!((e.mod(BigInteger.valueOf(4))).equals(0)) && ((e.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0)))){
- estring += e + " / ";
- e = e.divide(BigInteger.valueOf(2));
- }
- }
- estring += e;
- for(int i=0; i<buffer; i++){
- System.out.print(" ");
- }
- System.out.print("e = " + estring);
- if((e.compareTo(BigInteger.valueOf(3))) == 1){
- System.out.println(" ---" + doeverything(e));
- BigInteger d = sqrt(e);
- BigInteger e2 = e.subtract(d.multiply(d));
- buffer++;
- recursed(d);
- recursee(e2);
- buffer--;
- } else {
- System.out.println();
- System.out.println();
- }
- }
- public static String doeverything(BigInteger c){
- ArrayList<ArrayList<BigInteger>> factors = factorize(c);
- String thing = "\n";
- thing += forc(c);
- thing += forpairs(factors);
- return thing;
- }
- public static String forc(BigInteger c){
- String thing = "";
- BigInteger d = sqrt(c);
- BigInteger e = c.subtract(d.multiply(d));
- BigInteger f = e.subtract((d.multiply(BigInteger.valueOf(2))).add(BigInteger.valueOf(1)));
- //Root of d
- thing += bufferadd();
- BigInteger rootofd_a = d;
- BigInteger rootofd_b = d.multiply(BigInteger.valueOf(9));
- BigCell rootofd = new BigCell(rootofd_a, rootofd_b);
- thing += "Root of d: " + rootofd.description();
- thing += "\n";
- //BigN and BigN-1
- thing += bufferadd();
- BigInteger bign = ((c.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2))).subtract(d);
- thing += "BigN = " + bign + ", BigN-1 = " + (bign.subtract(BigInteger.valueOf(1)));
- thing += "\n";
- //The cells in (e,1) and (f,1) where a[t]=BigN and a[t]=BigN-1
- thing += bufferadd();
- BigCell e1_bign = e1cell(e, bign);
- thing += "(e,1) a=BigN = ";
- thing += e1_bign.description() + " --- " + squaresum(e1_bign);
- thing += "\n";
- thing += bufferadd();
- BigCell f1_bign = f1cell(f, (bign.subtract(BigInteger.valueOf(1))));
- thing += "(f,1) a=BigN-1 = ";
- thing += f1_bign.description() + " --- " + squaresum(f1_bign);
- thing += "\n";
- //The cells in (e,1) and (f,1) where a[t]=c*BigN and c*(BigN-1)
- thing += bufferadd();
- BigInteger cbign = c.multiply(bign);
- BigInteger cbignm1 = c.multiply(bign.subtract(BigInteger.valueOf(1)));
- BigCell e1_cbign = e1cell(e, cbign);
- thing += "(e,1) a=c*BigN = ";
- thing += e1_cbign.description() + " --- " + squaresum(e1_cbign);
- thing += "\n";
- thing += bufferadd();
- BigCell f1_cbignm1 = f1cell(f, cbignm1);
- thing += "(f,1) a=c*(BigN-1) = ";
- thing += f1_cbignm1.description() + " --- " + squaresum(f1_cbignm1);
- thing += "\n";
- //The cells in (e,1) and (f,1) where a[t]=c(c-BigN+1) and c(c-BigN+2)
- thing += bufferadd();
- BigInteger cshadown = c.multiply(c.subtract(bign).add(BigInteger.valueOf(1)));
- BigInteger cshadownp1 = c.multiply(c.subtract(bign).add(BigInteger.valueOf(2)));
- BigCell e1_cshadown = e1cell(e, cshadown);
- thing += "(e,1) a=c*(c-BigN+1) = ";
- thing += e1_cshadown.description() + " --- " + squaresum(e1_cshadown);
- thing += "\n";
- thing += bufferadd();
- BigCell f1_cshadownp1 = f1cell(f, cshadownp1);
- thing += "(f,1) a=c*(c-BigN+2) = ";
- thing += f1_cshadownp1.description() + " --- " + squaresum(f1_cshadownp1);
- thing += "\n";
- //The cells in (e,1) and (f,1) where x+x=2f+1
- BigInteger twofp1 = (f.multiply(BigInteger.valueOf(-2))).add(BigInteger.valueOf(1));
- thing += xplusxstring("2f+1 (x=f or f+1)", twofp1, "filler", BigInteger.valueOf(2), e, f);
- //The cells in (e,1) and (f,1) where x+x=2d+1
- BigInteger twodp1 = (d.multiply(BigInteger.valueOf(2))).add(BigInteger.valueOf(1));
- thing += xplusxstring("2d+1", twodp1, "filler", BigInteger.valueOf(2), e, f);
- //The cells in (e,1) and (f,1) where x+x=BigN or BigN-1
- thing += xplusxstring("BigN", bign, "BigN-1", (bign.subtract(BigInteger.valueOf(1))), e, f);
- //The cells in (e,1) and (f,1) where x+x=c*BigN or c*BigN-1
- thing += xplusxstring("c*BigN", cbign, "c*(BigN-1)", cbignm1, e, f);
- //The cells in (e,1) and (f,1) where x+x=c(c-BigN+1) or c(c-BigN+2)
- thing += xplusxstring("c*(c-BigN+1)", cshadown, "c*(c-BigN+2)", cshadownp1, e, f);
- return thing;
- }
- public static String forpairs(ArrayList<ArrayList<BigInteger>> factors){
- String thing = "";
- for(int i=0; i<factors.size(); i++){
- if(((factors.get(i).get(0).add(factors.get(i).get(1))).mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- BigInteger a = factors.get(i).get(0);
- BigInteger b = factors.get(i).get(1);
- thing += bufferadd();
- thing += factors.get(i);
- thing += "\n";
- buffer++;
- //The (e,n) cell
- BigCell paircell = new BigCell(a, b);
- thing += bufferadd();
- thing += "(e,n) cell = " + paircell.description();
- thing += "\n";
- //(a-1)(b-1) and /2
- BigInteger a1b1 = (a.subtract(BigInteger.valueOf(1))).multiply(b.subtract(BigInteger.valueOf(1)));
- BigInteger a1b1over2 = a1b1.divide(BigInteger.valueOf(2));
- thing += bufferadd();
- thing += "(a-1)(b-1) = " + a1b1 + ", /2 (BigN-n) = " + a1b1over2;
- thing += "\n";
- //the (x+n)(x+n) square, its triangles, and its nn+2d(n-1)+f-1 configuration
- BigInteger xplusnsquared = paircell.xplusnsquared();
- BigInteger tri1 = BigInteger.valueOf(0);
- BigInteger tri2 = BigInteger.valueOf(0);
- String triout = "error in trioutput";
- if((xplusnsquared.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- BigInteger overfour = xplusnsquared.divide(BigInteger.valueOf(4));
- for(BigInteger k = BigInteger.valueOf(0); (k.compareTo(overfour))==-1; k = k.add(BigInteger.valueOf(1))){
- BigInteger testtri1 = (k.multiply(k.subtract(BigInteger.valueOf(1)))).divide(BigInteger.valueOf(2));
- BigInteger testtri2 = ((k.subtract(BigInteger.valueOf(1))).multiply(k.subtract(BigInteger.valueOf(2)))).divide(BigInteger.valueOf(2));
- if(overfour.equals(testtri1.add(testtri2))){
- tri1 = testtri1;
- tri2 = testtri2;
- triout = "(x+n)(x+n) is " + xplusnsquared + ", which is (4*" + tri1 + ")+(4*" + tri2 + ") (u=" + (k.subtract(BigInteger.valueOf(1))) + "&" + k + ")";
- }
- }
- } else {
- BigInteger minusone = xplusnsquared.subtract(BigInteger.valueOf(1));
- tri1 = minusone.divide(BigInteger.valueOf(8));
- triout = "(x+n)(x+n) is " + xplusnsquared + ", which is (8*" + tri1 + ")+1 (u=" + paircell.u() + ")";
- }
- triout+="\n";
- triout+=bufferadd();
- BigInteger nn = paircell.n().multiply(paircell.n());
- BigInteger twodnm1 = (paircell.d().multiply(BigInteger.valueOf(2))).multiply(paircell.n().subtract(BigInteger.valueOf(1)));
- BigInteger posf = paircell.f().multiply(BigInteger.valueOf(-1));
- triout+="nn+2d(n-1)+f-1 = " + nn + "+" + twodnm1 + "+" + posf + "-1";
- thing += bufferadd();
- thing += triout;
- thing += "\n";
- //the 2(x+n)2(x+n) square, its triangles, and its nn+2d(n-1)+f-1 configuration
- BigInteger xplusnsquared2 = (paircell.xplusn().multiply(BigInteger.valueOf(2))).multiply(paircell.xplusn().multiply(BigInteger.valueOf(2)));
- String triout2 = "error in trioutput2";
- BigInteger tri12 = BigInteger.valueOf(0);
- BigInteger tri22 = BigInteger.valueOf(0);
- BigInteger overfour2 = xplusnsquared2.divide(BigInteger.valueOf(4)); //since it's *2 it'll always be evens
- for(BigInteger k2 = BigInteger.valueOf(0); (k2.compareTo(overfour2)) == -1; k2 = k2.add(BigInteger.valueOf(1))){
- BigInteger testtri12 = (k2.multiply(k2.subtract(BigInteger.valueOf(1)))).divide(BigInteger.valueOf(2));
- BigInteger testtri22 = ((k2.subtract(BigInteger.valueOf(1))).multiply(k2.subtract(BigInteger.valueOf(2)))).divide(BigInteger.valueOf(2));
- if(overfour2.equals(testtri12.add(testtri22))){
- tri12 = testtri12;
- tri22 = testtri22;
- triout2 = "(2(x+n))(2(x+n)) is " + xplusnsquared2 + ", which is (4*" + tri12 + ")+(4*" + tri22 + ") (u=" + (k2.subtract(BigInteger.valueOf(1))) + "&" + k2 + ")";
- }
- }
- thing += bufferadd();
- thing += triout2;
- thing += "\n";
- //(0,n) a=aa b=bb
- thing += bufferadd();
- BigCell zeron_aabb_cell = zeron_aabb(paircell);
- BigInteger n_aabb = zeron_aabb_cell.n();
- thing += "(0,n) aa,bb = ";
- thing += zeron_aabb_cell.description();
- thing += "\n";
- //(0,n) a=ab b=ab
- thing += bufferadd();
- BigCell zeron_ab_ab_cell = zeron_ab_ab(paircell);
- thing += "(0,n) ab,ab = ";
- thing += zeron_ab_ab_cell.description();
- thing += "\n";
- //(0,n) a=a b=abb
- thing += bufferadd();
- BigCell zeron_a_abb_cell = zeron_a_abb(paircell);
- thing += "(0,n) a,abb = ";
- thing += zeron_a_abb_cell.description();
- thing += "\n";
- //(0,n) a=b b=aab
- thing += bufferadd();
- BigCell zeron_b_aab_cell = zeron_b_aab(paircell);
- thing += "(0,n) b,aab = ";
- thing += zeron_b_aab_cell.description();
- thing += "\n";
- //(0,n) a=1 b=cc
- thing += bufferadd();
- BigCell zeron_1cc_cell = zeron_1cc(paircell);
- thing += "(0,n) 1,cc = ";
- thing += zeron_1cc_cell.description();
- thing += "\n";
- //the cell in (1,1) where d is equal to the n value for the aa bb cell
- thing += bufferadd();
- BigCell oneone_d_aabbn_cell = oneone_d_aabbn(n_aabb);
- thing += "(1,1) d=aabbn = ";
- thing += oneone_d_aabbn_cell.description();
- thing += "\n";
- //the cell in (0,1) where a is equal to the n value for the aa bb cell
- thing += bufferadd();
- BigCell zeroone_a_aabbn_cell = zeroone_a_aabbn(n_aabb);
- thing += "(0,1) a=aabbn = ";
- thing += zeroone_a_aabbn_cell.description();
- thing += "\n";
- //(e,1) na
- thing += bufferadd();
- BigCell e1_na = e1cell(paircell.e(), (paircell.n().multiply(paircell.a())));
- thing += "(e,1) a=na = ";
- thing += e1_na.description() + " --- " + squaresum(e1_na);
- thing += "\n";
- //(f,1) a(n-1)
- thing += bufferadd();
- BigCell f1_na = f1cell(paircell.f(), (paircell.a().multiply(paircell.n().subtract(BigInteger.valueOf(1)))));
- thing += "(f,1) a=a(n-1) = ";
- thing += f1_na.description() + " --- " + squaresum(f1_na);
- thing += "\n";
- //(e,1) bn
- thing += bufferadd();
- BigCell e1_bn = e1cell(paircell.e(), (paircell.b().multiply(paircell.n())));
- thing += "(e,1) a=bn = ";
- thing += e1_bn.description() + " --- " + squaresum(e1_bn);
- thing += "\n";
- //(f,1) b(n-1)
- thing += bufferadd();
- BigCell f1_bn = f1cell(paircell.f(), (paircell.b().multiply(paircell.n().subtract(BigInteger.valueOf(1)))));
- thing += "(f,1) a=b(n-1) = ";
- thing += f1_bn.description() + " --- " + squaresum(f1_bn);
- thing += "\n";
- //the cells in (e,1) and (f,1) for which x+x=an or a(n-1) and the same for bn or b(n-1) (whichever's odd, if any)
- thing += xplusxstring("an", e1_na.a(), "a(n-1)", f1_na.a(), paircell.e(), paircell.f());
- thing += xplusxstring("bn", e1_bn.a(), "b(n-1)", f1_bn.a(), paircell.e(), paircell.f());
- buffer--;
- }
- }
- return thing;
- }
- public static ArrayList<ArrayList<BigInteger>> factorize(BigInteger c){
- ArrayList<ArrayList<BigInteger>> factors = new ArrayList<ArrayList<BigInteger>>();
- BigInteger d = sqrt(c);
- BigInteger highest = (((c.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2))).subtract(d)).add(BigInteger.valueOf(2));
- BigInteger n = BigInteger.valueOf(1);
- while(n.compareTo(highest) == -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))));
- //For some weird reason, even though it's the same calculation as the one used for ints, this doesn't work
- //I have no idea why
- //So I'm adding one to b and taking one away from a because it magically fixes everything
- //a = a.subtract(BigInteger.valueOf(1));
- //b = b.add(BigInteger.valueOf(1));
- BigInteger testc = a.multiply(b);
- if(testc.equals(c)){
- ArrayList<BigInteger> pair = new ArrayList<BigInteger>();
- pair.add(a);
- pair.add(b);
- factors.add(pair);
- }
- n = n.add(BigInteger.valueOf(1));
- }
- return factors;
- }
- public static String bufferadd(){
- String returnbuffer = "";
- for(int i=0; i<buffer+1; i++){
- returnbuffer+=" ";
- }
- return returnbuffer;
- }
- public static BigCell zeron_aabb(BigCell cell){
- BigInteger a = cell.a().multiply(cell.a());
- BigInteger b = cell.b().multiply(cell.b());
- BigCell returncell = new BigCell(a,b);
- return returncell;
- }
- public static BigCell zeron_1cc(BigCell cell){
- BigInteger a = BigInteger.valueOf(1);
- BigInteger b = cell.c().multiply(cell.c());
- BigCell returncell = new BigCell(a,b);
- return returncell;
- }
- public static BigCell zeron_a_abb(BigCell cell){
- BigInteger a = cell.a();
- BigInteger b = cell.b().multiply(cell.b().multiply(cell.a()));
- BigCell returncell = new BigCell(a,b);
- return returncell;
- }
- public static BigCell zeron_ab_ab(BigCell cell){
- BigInteger a = cell.a().multiply(cell.b());
- BigInteger b = cell.a().multiply(cell.b());
- BigCell returncell = new BigCell(a,b);
- return returncell;
- }
- public static BigCell zeron_b_aab(BigCell cell){
- BigInteger a = cell.b();
- BigInteger b = cell.b().multiply(cell.a().multiply(cell.a()));
- BigCell returncell = new BigCell(a,b);
- return returncell;
- }
- public static BigCell oneone_d_aabbn(BigInteger d){
- BigInteger e = BigInteger.valueOf(1);
- BigInteger n = BigInteger.valueOf(1);
- BigInteger f = (e.subtract((d.multiply(BigInteger.valueOf(2))).add(BigInteger.valueOf(1)))).multiply(BigInteger.valueOf(-1));
- BigInteger rootf = sqrt(f);
- BigInteger x = rootf.subtract(BigInteger.valueOf(1));
- BigInteger a = d.subtract(x);
- BigInteger b = a.add((x.multiply(BigInteger.valueOf(2))).add(n.multiply(BigInteger.valueOf(2))));
- BigCell returncell = new BigCell(a,b);
- return returncell;
- }
- public static BigCell zeroone_a_aabbn(BigInteger a){
- BigInteger e = BigInteger.valueOf(0);
- BigInteger n = BigInteger.valueOf(1);
- BigInteger twoname = (n.multiply(a.multiply(BigInteger.valueOf(2)))).subtract(e);
- BigInteger x = sqrt(twoname);
- BigInteger b = a.add((x.multiply(BigInteger.valueOf(2))).add(n.multiply(BigInteger.valueOf(2))));
- BigCell returncell = new BigCell(a,b);
- return returncell;
- }
- public static String squaresum(BigCell cell){
- BigInteger e = cell.e();
- BigInteger a = cell.a();
- BigInteger t = cell.t();
- String returnstring = "";
- if((e.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- BigInteger eover2 = e.divide(BigInteger.valueOf(2));
- BigInteger asquares = a.subtract(eover2);
- BigInteger asquare = asquares.divide(BigInteger.valueOf(2));
- returnstring = "a[t] = sq+sq+e/2 = " + asquare + "+" + asquare + "+" + eover2;
- } else {
- BigInteger eminus1over2 = (e.subtract(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
- BigInteger afirstsquare = (t.subtract(BigInteger.valueOf(1))).multiply(t.subtract(BigInteger.valueOf(1)));
- BigInteger asecondsquare = t.multiply(t);
- returnstring = "a[t] = sq+(sq)+(e-1)/2 = " + afirstsquare + "+" + asecondsquare + "+" + eminus1over2;
- }
- return returnstring;
- }
- public static BigCell e1cell(BigInteger e, BigInteger value){
- BigInteger n = BigInteger.valueOf(1);
- BigInteger a = value;
- BigInteger twoname = (n.multiply(a.multiply(BigInteger.valueOf(2)))).subtract(e);
- BigInteger x = sqrt(twoname);
- BigInteger b = a.add(x.multiply(BigInteger.valueOf(2))).add(n.multiply(BigInteger.valueOf(2)));
- BigCell returncell = new BigCell(a,b);
- return returncell;
- }
- public static BigCell f1cell(BigInteger f, BigInteger value){
- BigInteger n = BigInteger.valueOf(1);
- BigInteger a = value;
- BigInteger twonamf = (n.multiply(a.multiply(BigInteger.valueOf(2)))).subtract(f);
- BigInteger x = sqrt(twonamf);
- BigInteger b = a.add(x.multiply(BigInteger.valueOf(2))).add(n.multiply(BigInteger.valueOf(2)));
- BigCell returncell = new BigCell(a,b,f);
- return returncell;
- }
- public static ArrayList<BigCell> xplusx(BigInteger value, BigInteger e, BigInteger f){
- if((value.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- value = value.add(BigInteger.valueOf(1)); //not the best fix but I'll only be using it for odds anyway
- }
- BigInteger halflow = value.divide(BigInteger.valueOf(2));
- BigInteger halfhigh = halflow.add(BigInteger.valueOf(1)); //the two values that add to make value
- BigInteger xneg = BigInteger.valueOf(0);
- BigInteger xpos = BigInteger.valueOf(0);
- if((e.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){ //e has even x, f has odd x
- if((halflow.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- xpos = halflow;
- xneg = halfhigh;
- } else {
- xpos = halfhigh;
- xneg = halflow;
- }
- } else { //e has odd x, f has even x
- if((halflow.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
- xpos = halfhigh;
- xneg = halflow;
- } else {
- xpos = halflow;
- xneg = halfhigh;
- }
- }
- BigInteger n = BigInteger.valueOf(1);
- BigInteger aneg = ((xneg.multiply(xneg)).add(f)).divide(BigInteger.valueOf(2));
- BigInteger apos = ((xpos.multiply(xpos)).add(e)).divide(BigInteger.valueOf(2));
- BigInteger bneg = aneg.add(BigInteger.valueOf(2)).add(xneg.multiply(BigInteger.valueOf(2)));
- BigInteger bpos = apos.add(BigInteger.valueOf(2)).add(xpos.multiply(BigInteger.valueOf(2)));
- BigCell fcell = new BigCell(aneg, bneg, f);
- BigCell ecell = new BigCell(apos, bpos);
- ArrayList<BigCell> returncells = new ArrayList<BigCell>();
- returncells.add(fcell);
- returncells.add(ecell);
- return returncells;
- }
- public static String xplusxstring(String type1, BigInteger value1, String type2, BigInteger value2, BigInteger e, BigInteger f){
- String thing = "";
- thing += bufferadd();
- if(value1.mod(BigInteger.valueOf(2)).equals(BigInteger.valueOf(1))){
- thing += "The cells in (e,1) and (f,1) where x+x=" + type1 + "=" + value1 + "\n";
- buffer++;
- thing += bufferadd();
- ArrayList<BigCell> pair = xplusx(value1, e, f);
- thing += pair.get(0).description() + "\n" + bufferadd();
- thing += pair.get(1).description() + "\n";
- buffer--;
- } else if(value2.mod(BigInteger.valueOf(2)).equals(BigInteger.valueOf(1))){
- thing += "The cells in (e,1) and (f,1) where x+x=" + type2 + "=" + value2 + "\n";
- buffer++;
- thing += bufferadd();
- ArrayList<BigCell> pair = xplusx(value2, e, f);
- thing += pair.get(0).description() + "\n" + bufferadd();
- thing += pair.get(1).description() + "\n";
- buffer--;
- } else {
- thing += "Neither of " + type1 + " and " + type2 + " are odd, so here's where x+x=" + type1 + "+1=" + (value1.add(BigInteger.valueOf(1))) + " (using x from (e,1) and (f,1)):\n";
- buffer++;
- thing += bufferadd();
- ArrayList<BigCell> pair = xplusx((value1.add(BigInteger.valueOf(1))), e, f);
- thing += pair.get(0).description() + "\n" + bufferadd();
- thing += pair.get(1).description() + "\n";
- buffer--;
- }
- return thing;
- }
- public static BigInteger sqrt(BigInteger x) {
- if(x.equals(BigInteger.ZERO)){
- return BigInteger.ZERO;
- }
- 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))){
- return returnvalue;
- } else {
- return returnvalue.subtract(BigInteger.valueOf(1));
- }
- }
- }
- /**
- * Things to potentially add:
- * - all (0,n) cells for d*d
- * - the (e,n) cell for which (e+2n,n) is the solution record for each ab pair
- * - the (f,n) cell for which (f+2(n-1),n) is the solution record for each ab pair
- */
Advertisement
Add Comment
Please, Sign In to add comment