Guest User

BigCell.java

a guest
Dec 21st, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 KB | None | 0 0
  1. import java.util.*;
  2. import java.math.*;
  3.  
  4. public class BigCell{
  5. //VB for variable so it doesn't interfere with simple getter names
  6. private BigInteger iVB;
  7. private BigInteger jVB;
  8. private BigInteger aVB;
  9. private BigInteger bVB;
  10. private BigInteger cVB;
  11. private BigInteger dVB;
  12. private BigInteger eVB;
  13. private BigInteger fVB;
  14. private BigInteger nVB;
  15. private BigInteger xVB;
  16. private BigInteger tVB;
  17. private BigInteger xplusnVB;
  18. private BigInteger dplusnVB;
  19. private BigInteger xplusnsquaredVB;
  20. private BigInteger dplusnsquaredVB;
  21. private BigInteger uVB;
  22. private BigInteger bignVB;
  23. private BigInteger naVB;
  24. private boolean oddxplusnsquaredVB;
  25. private String descriptionV;
  26.  
  27. public BigCell(String aSend, String bSend){
  28. this(new BigInteger(aSend), new BigInteger(bSend));
  29. }
  30.  
  31. public BigCell(String aSend, String bSend, String fSend){
  32. this(new BigInteger(aSend), new BigInteger(bSend), new BigInteger(fSend));
  33. }
  34.  
  35. public BigCell(BigInteger aSend, BigInteger bSend){
  36. aVB = aSend;
  37. bVB = bSend;
  38. cVB = aVB.multiply(bVB);
  39. dVB = sqrt(cVB);
  40. eVB = cVB.subtract(dVB.multiply(dVB));
  41. fVB = eVB.subtract((dVB.multiply(BigInteger.valueOf(2))).add(BigInteger.valueOf(1)));
  42. nVB = ((aVB.add(bVB)).divide(BigInteger.valueOf(2))).subtract(dVB);
  43. xVB = dVB.subtract(aVB);
  44. tVB = BigInteger.valueOf(0);
  45. if((eVB.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
  46. tVB = (xVB.add(BigInteger.valueOf(2))).divide(BigInteger.valueOf(2));
  47. } else {
  48. tVB = (xVB.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
  49. }
  50. iVB = nVB.add(dVB);
  51. jVB = bVB.subtract(iVB);
  52. xplusnVB = xVB.add(nVB);
  53. dplusnVB = dVB.add(nVB);
  54. xplusnsquaredVB = xplusnVB.multiply(xplusnVB);
  55. dplusnsquaredVB = dplusnVB.multiply(dplusnVB);
  56. uVB = BigInteger.valueOf(0);
  57. oddxplusnsquaredVB = true;
  58. if((xplusnsquaredVB.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
  59. oddxplusnsquaredVB = false;
  60. uVB = xplusnVB.divide(BigInteger.valueOf(2));
  61. } else {
  62. uVB = (xplusnVB.subtract(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
  63. }
  64. bignVB = ((cVB.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2))).subtract(dVB);
  65. descriptionV = "("+eVB+","+nVB+","+tVB+") = {"+eVB+":"+nVB+":"+dVB+":"+xVB+":"+aVB+":"+bVB+"}, f="+fVB+", c="+cVB+", u="+uVB+", i="+iVB+", j="+jVB;
  66. }
  67.  
  68. public BigCell(BigInteger aSend, BigInteger bSend, BigInteger fSend){
  69. aVB = aSend;
  70. bVB = bSend;
  71. cVB = aVB.multiply(bVB);
  72. dVB = (sqrt(cVB)).add(BigInteger.valueOf(1));
  73. eVB = fSend;
  74. fVB = eVB.add((dVB.multiply(BigInteger.valueOf(2))).subtract(BigInteger.valueOf(1)));
  75. nVB = ((aVB.add(bVB)).divide(BigInteger.valueOf(2))).subtract(dVB);
  76. xVB = dVB.subtract(aVB);
  77. tVB = BigInteger.valueOf(0);
  78. if((eVB.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
  79. tVB = (xVB.add(BigInteger.valueOf(2))).divide(BigInteger.valueOf(2));
  80. } else {
  81. tVB = (xVB.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
  82. }
  83. iVB = nVB.add(dVB);
  84. jVB = bVB.subtract(iVB);
  85. xplusnVB = xVB.add(nVB);
  86. dplusnVB = dVB.add(nVB);
  87. xplusnsquaredVB = xplusnVB.multiply(xplusnVB);
  88. dplusnsquaredVB = dplusnVB.multiply(dplusnVB);
  89. uVB = BigInteger.valueOf(0);
  90. oddxplusnsquaredVB = true;
  91. if((xplusnsquaredVB.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
  92. oddxplusnsquaredVB = false;
  93. uVB = xplusnVB.divide(BigInteger.valueOf(2));
  94. } else {
  95. uVB = (xplusnVB.subtract(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2));
  96. }
  97. bignVB = ((cVB.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2))).subtract(dVB);
  98. descriptionV = "("+eVB+","+nVB+","+tVB+") = {"+eVB+":"+nVB+":"+dVB+":"+xVB+":"+aVB+":"+bVB+"}, f="+fVB+", c="+cVB+", u="+uVB+", i="+iVB+", j="+jVB;
  99. }
  100.  
  101. public static BigInteger sqrt(BigInteger x) {
  102. if(x.equals(BigInteger.ZERO)){
  103. return BigInteger.ZERO;
  104. }
  105. boolean negative = false;
  106. if(x.compareTo(BigInteger.valueOf(0)) == -1){
  107. negative = true;
  108. x = x.multiply(BigInteger.valueOf(-1));
  109. }
  110. BigInteger div = BigInteger.ZERO.setBit(x.bitLength()/2);
  111. BigInteger div2 = div;
  112. BigInteger returnvalue = BigInteger.valueOf(0);
  113. // Loop until we hit the same value twice in a row, or wind
  114. // up alternating.
  115. for(;;) {
  116. BigInteger y = div.add(x.divide(div)).shiftRight(1);
  117. if (y.equals(div) || y.equals(div2)){
  118. returnvalue = y;
  119. break;
  120. }
  121. div2 = div;
  122. div = y;
  123. }
  124.  
  125. BigInteger testsquare = returnvalue.multiply(returnvalue);
  126. BigInteger testp1square = (returnvalue.add(BigInteger.valueOf(1))).multiply(returnvalue.add(BigInteger.valueOf(1)));
  127. if((testsquare.equals(x)) || (((testsquare.compareTo(x)) == -1) && ((testp1square.compareTo(x)) == 1))){
  128. if(negative){
  129. returnvalue = returnvalue.multiply(BigInteger.valueOf(-1)); //hacky fix to very specific problem
  130. }
  131. return returnvalue;
  132. } else {
  133. return returnvalue.subtract(BigInteger.valueOf(1));
  134. }
  135. }
  136.  
  137. public BigInteger a(){
  138. return aVB;
  139. }
  140.  
  141. public BigInteger b(){
  142. return bVB;
  143. }
  144.  
  145. public BigInteger c(){
  146. return cVB;
  147. }
  148.  
  149. public BigInteger d(){
  150. return dVB;
  151. }
  152.  
  153. public BigInteger e(){
  154. return eVB;
  155. }
  156.  
  157. public BigInteger f(){
  158. return fVB;
  159. }
  160.  
  161. public BigInteger n(){
  162. return nVB;
  163. }
  164.  
  165. public BigInteger x(){
  166. return xVB;
  167. }
  168.  
  169. public BigInteger t(){
  170. return tVB;
  171. }
  172.  
  173. public BigInteger i(){
  174. return iVB;
  175. }
  176.  
  177. public BigInteger j(){
  178. return jVB;
  179. }
  180.  
  181. public BigInteger xplusn(){
  182. return xplusnVB;
  183. }
  184.  
  185. public BigInteger dplusn(){
  186. return dplusnVB;
  187. }
  188.  
  189. public BigInteger xplusnsquared(){
  190. return xplusnsquaredVB;
  191. }
  192.  
  193. public BigInteger dplusnsquared(){
  194. return dplusnsquaredVB;
  195. }
  196.  
  197. public BigInteger u(){
  198. return uVB;
  199. }
  200.  
  201. public BigInteger bign(){
  202. return bignVB;
  203. }
  204.  
  205. public boolean oddxplusnsquared(){
  206. return oddxplusnsquaredVB;
  207. }
  208.  
  209. public void print(){
  210. System.out.println(descriptionV);
  211. }
  212.  
  213. public String description(){
  214. return descriptionV;
  215. }
  216.  
  217. public boolean isPrime(BigInteger c){
  218. if(c.equals(BigInteger.valueOf(1)) || c.mod(BigInteger.valueOf(2)).equals(BigInteger.valueOf(0))){
  219. return false;
  220. }
  221. BigInteger d = sqrt(c);
  222. BigInteger bign = ((c.add(BigInteger.valueOf(1))).divide(BigInteger.valueOf(2))).subtract(d);
  223. BigInteger n = BigInteger.valueOf(1);
  224. if((bign.mod(BigInteger.valueOf(2))).equals(BigInteger.valueOf(0))){
  225. n = n.add(BigInteger.valueOf(1));
  226. }
  227. while(n.compareTo(bign) == -1){
  228. BigInteger x = (sqrt(((d.add(n)).multiply(d.add(n))).subtract(c))).subtract(n);
  229. BigInteger a = d.subtract(x);
  230. BigInteger b = a.add((x.multiply(BigInteger.valueOf(2))).add(n.multiply(BigInteger.valueOf(2))));
  231. BigInteger testc = a.multiply(b);
  232. if(testc.equals(c)){
  233. return false;
  234. }
  235. n = n.add(BigInteger.valueOf(2));
  236. }
  237. return true;
  238. }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment