I have to write a code, that finds prime factorization of given number. The code have to give an 2-dimensional array back, that has the numbers on the first row and the powers on the second. I don't know how to save the results in this array.
public static long[][] primeFactorization(long l) {
//n = 6600 = 2^3*3^1*5^2*11^1
// z[0][4] = 2|3|5|11 - coefficient
// z[1][4] = 3|1|2|1 - power
int count = 0;
int i=2;
long[][] x = new long[2][];
while(l%2==0) {
l=l/2;
count++; //power 8 = 2.2.2 => count = 3
}
i++;
//ToDo: save i=2 in array[0][] = {2,...};
for (i = 3; i <= Math.sqrt(l); i = i+2) {
// While i divides l, print i and divide l
while (l%i == 0) {
int temp = i; //ToDo: save the divider in array[0][]
count++; //ToDo: save the power in array[1][]
l = l/i;
i = temp;
}
}
return x;
}
Ainarray[X][Y]" simply meansarray[X][Y] = A;