Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1 @@
public boolean prime(BigInteger i);

View file

@ -0,0 +1,12 @@
public static List<BigInteger> primeFactorBig(BigInteger a){
List<BigInteger> ans = new LinkedList<BigInteger>();
//loop until we test the number itself or the number is 1
for (BigInteger i = BigInteger.valueOf(2); i.compareTo(a) <= 0 && !a.equals(BigInteger.ONE);
i = i.add(BigInteger.ONE)){
while (a.remainder(i).equals(BigInteger.ZERO) && prime(i)) { //if we have a prime factor
ans.add(i); //put it in the list
a = a.divide(i); //factor it out of the number
}
}
return ans;
}

View file

@ -0,0 +1,32 @@
private static final BigInteger two = BigInteger.valueOf(2);
public List<BigInteger> primeDecomp(BigInteger a) {
// impossible for values lower than 2
if (a.compareTo(two) < 0) {
return null;
}
//quickly handle even values
List<BigInteger> result = new ArrayList<BigInteger>();
while (a.and(BigInteger.ONE).equals(BigInteger.ZERO)) {
a = a.shiftRight(1);
result.add(two);
}
//left with odd values
if (!a.equals(BigInteger.ONE)) {
BigInteger b = BigInteger.valueOf(3);
while (b.compareTo(a) < 0) {
if (b.isProbablePrime(10)) {
BigInteger[] dr = a.divideAndRemainder(b);
if (dr[1].equals(BigInteger.ZERO)) {
result.add(b);
a = dr[0];
}
}
b = b.add(two);
}
result.add(b); //b will always be prime here...
}
return result;
}

View file

@ -0,0 +1,43 @@
private static final BigInteger TWO = BigInteger.valueOf(2);
private static final BigInteger THREE = BigInteger.valueOf(3);
private static final BigInteger FIVE = BigInteger.valueOf(5);
public static ArrayList<BigInteger> primeDecomp(BigInteger n){
if(n.compareTo(TWO) < 0) return null;
ArrayList<BigInteger> factors = new ArrayList<BigInteger>();
// handle even values
while(n.and(BigInteger.ONE).equals(BigInteger.ZERO)){
n = n.shiftRight(1);
factors.add(TWO);
}
// handle values divisible by three
while(n.mod(THREE).equals(BigInteger.ZERO)){
factors.add(THREE);
n = n.divide(THREE);
}
// handle values divisible by five
while(n.mod(FIVE).equals(BigInteger.ZERO)){
factors.add(FIVE);
n = n.divide(FIVE);
}
// much like how we can skip multiples of two, we can also skip
// multiples of three and multiples of five. This increment array
// helps us to accomplish that
int[] pattern = {4,2,4,2,4,6,2,6};
int pattern_index = 0;
BigInteger current_test = BigInteger.valueOf(7);
while(!n.equals(BigInteger.ONE)){
while(n.mod(current_test).equals(BigInteger.ZERO)){
factors.add(current_test);
n = n.divide(current_test);
}
current_test = current_test.add(BigInteger.valueOf(pattern[pattern_index]));
pattern_index = (pattern_index + 1) & 7;
}
return factors;
}

View file

@ -0,0 +1,11 @@
public static List<BigInteger> primeFactorBig(BigInteger a){
List<BigInteger> ans = new LinkedList<BigInteger>();
for(BigInteger divisor = BigInteger.valueOf(2);
a.compareTo(ONE) > 0; divisor = divisor.add(ONE))
while(a.mod(divisor).equals(ZERO)){
ans.add(divisor);
a = a.divide(divisor);
}
return ans;
}