Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- public class List_a_of_t_eq_c {
- private static BigInteger zero = BigInteger.ZERO;
- private static BigInteger one = BigInteger.ONE;
- private static BigInteger two = BigInteger.valueOf(2);
- private static BigInteger four = BigInteger.valueOf(4);
- private static BigInteger eight = BigInteger.valueOf(8);
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- for (;;) {
- BigInteger c = s.nextBigInteger();
- BigInteger _2c = c.multiply(two);
- BigInteger d = sqrt(c);
- BigInteger e = c.subtract(d.pow(2));
- BigInteger t = one;
- BigInteger e_t = _2c;
- BigInteger gap = four;
- if (e.and(one).equals(zero)) {
- gap = four;
- }
- while (!lt(e_t, _2c.negate())) {
- VQCElement occurrence = getRecord(e_t, one, t);
- t = t.add(one);
- e_t = e_t.subtract(gap);
- System.out.println(occurrence.toString());
- gap = gap.add(eight);
- }
- System.out.println();
- }
- }
- private static VQCElement getRecord(BigInteger e, BigInteger n, BigInteger t) {
- VQCElement v = new VQCElement();
- v.e = e;
- v.n = n;
- v.t = t;
- v.x = getX(e, t);
- v.a = (v.x.pow(2)).add(e).divide(two.multiply(v.n));
- v.d = v.a.add(v.x);
- v.b = v.a.add(two.multiply(v.x)).add(two.multiply(v.n));
- v.c = v.a.multiply(v.b);
- return v;
- }
- private static BigInteger getX(BigInteger e, BigInteger t) {
- BigInteger subtrahend = one;
- if (e.and(one).equals(zero)) {
- subtrahend = two;
- }
- return two.multiply(t).subtract(subtrahend);
- }
- public static boolean gt(BigInteger i, BigInteger i2) {
- int result = i.compareTo(i2);
- return result > 0;
- }
- private static boolean lt(BigInteger i, BigInteger i2) {
- int result = i.compareTo(i2);
- return result < 0;
- }
- /** define d(n) = sqrt(n)//1*/
- private static BigInteger sqrt(BigInteger i) {
- BigInteger n = zero;
- BigInteger p = zero;
- if (i.equals(zero)) {
- return zero;
- } else if (i.equals(one)) {
- return one;
- } else if (i.equals(two)) {
- return one;
- } else if (i.equals(BigInteger.valueOf(3))) {
- return one;
- } else if (i.equals(BigInteger.valueOf(4))) {
- return two;
- } else if (i.equals(BigInteger.valueOf(5))) {
- return two;
- }
- BigInteger high = i.shiftRight(1);
- BigInteger low = zero;
- //high > low + 1
- while (gt(high, low.add(one))) {
- //n = (high + low) >> 1;
- n = (high.add(low)).shiftRight(1);
- p = n.multiply(n);
- int result = i.compareTo(p);
- if (result < 0) {
- high = n;
- } else if (result > 0) {
- low = n;
- } else {
- break;
- }
- }
- if (i.equals(p)) {
- return n;
- } else {
- return low;
- }
- }
- @SuppressWarnings({"StringConcatenationInsideStringBufferAppend", "StringBufferReplaceableByString"})
- static class VQCElement {
- public BigInteger a;
- public BigInteger b;
- public BigInteger c;
- public BigInteger d;
- public BigInteger e;
- public BigInteger i;
- public BigInteger n;
- public BigInteger x;
- public BigInteger t;
- public String getCoordinates() {
- return "(" + e + ", " + n + ", " + t + ")";
- }
- public String toString() {
- return "{" + e + ":" + n + ":" + d + ":" + x + ":" + a + ":" + b + "} " + getCoordinates();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment