Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.math.BigInteger;
- public class vqc{
- private static final BigInteger minusOne = BigInteger.valueOf(-1);
- private static final BigInteger zero = BigInteger.valueOf(0);
- private static final BigInteger one = BigInteger.valueOf(1);
- private static final BigInteger two = BigInteger.valueOf(2);
- private static final BigInteger four = BigInteger.valueOf(4);
- public static void main(String[] args){
- Scanner scan = new Scanner(System.in);
- System.out.println("c=");
- BigInteger c = zero;
- try{
- c = new BigInteger(scan.nextLine());
- } catch(Exception e){
- System.err.println("c is supposed to be a number");
- return;
- }
- while((c.mod(four)).equals(two)){
- c = c.divide(two);
- }
- BigInteger d = sqrt(c);
- BigInteger e = c.subtract(d.multiply(d));
- BigInteger n = factor(d, e);
- }
- public static BigInteger factor(BigInteger d, BigInteger e){
- BigInteger c = (d.multiply(d)).add(e);
- BigInteger cBigNx = c.subtract(d);
- BigInteger cBigNt = zero;
- if((e.mod(two)).equals(zero)){
- cBigNt = (cBigNx.add(two)).divide(two);
- } else {
- cBigNt = (cBigNx.add(one)).divide(two);
- }
- Element aLow = e1Element(e, zero); //t=0
- Element aHigh = e1Element(e, cBigNt); //a[t]=c*BigN
- /*
- while(!((aLow.a()).equals(aHigh.a()))){
- if(isOddType1(c)){
- //something
- } else if(isOddType2(c)){
- //something
- } else if(isOddType3(c)){
- //something
- } else if(isOddType4(c)){
- //something
- }
- }
- */
- return zero;
- }
- public static BigInteger sqrt(BigInteger x) {
- if(x.compareTo(zero) == -1){
- x = x.multiply(minusOne);
- }
- if(x.equals(zero)){
- return zero;
- }
- BigInteger div = zero.setBit(x.bitLength()/2);
- BigInteger div2 = div;
- BigInteger returnvalue = zero;
- 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(one)).multiply(returnvalue.add(one));
- if((testsquare.equals(x)) || (((testsquare.compareTo(x)) == -1) && ((testp1square.compareTo(x)) == 1))){
- return returnvalue;
- } else {
- return returnvalue.subtract(one);
- }
- }
- public static Element e1Element(BigInteger e, BigInteger t){
- BigInteger x = zero;
- if((e.mod(two)).equals(zero)){
- x = (t.subtract(one)).multiply(two);
- } else {
- x = (t.multiply(two)).subtract(one);
- }
- BigInteger xx = x.multiply(x);
- BigInteger xxpe = xx.add(e);
- BigInteger a = ((x.multiply(x)).add(e)).divide(two);
- BigInteger b = a.add(x.multiply(two)).add(two);
- if(e.compareTo(zero) == -1){
- return new Element(a, b, e); //(f,1)
- } else {
- return new Element(a, b); //(e,1)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement