我必须写一个代码,找到给定数字的质因数分解。代码必须返回一个二维数组,第一行是数字,第二行是幂。我不知道如何将结果保存在这个数组中。
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;
}
潇湘沐
12345678_0001
相关分类