/**
* 大数字相乘
*/
public class Test1 {
/**
* ints * num
* @param ints
* @param num
* @return
*/
public static int[] mul(int[] ints,int num){
for (int i = 0; i < ints.length; i++) {
ints[i] *= num;
}
for (int i = ints.length-1; i > 0; i--) {
ints[i-1] += ints[i]/10;
ints[i] = ints[i]%10;
}
return ints;
}
private static void console(int[] ints){
boolean flag = true;
for (int i = 0; i < ints.length; i++) {
if (flag){
if (ints[i]!=0){
System.out.print(ints[i]);
flag = false;
}
}else {
System.out.print(ints[i]);
}
}
System.out.println();
}
/**
* num的阶乘
* @param num
*/
public static int[] factorial(int num){
int[] ints = new int[200];
ints[ints.length-1] = 1;
for (int i = 1; i <= num; i++) {
ints = mul(ints,i);
}
return ints;
}
public static void main(String[] args) {
int[] i = {1,1,0};
int num = 11;
// 110 * 11
console(mul(i, num));
// console(factorial(50));//30414093201713378043612608166064768844377641568960512000000000000
}
}
原文地址:https://www.cnblogs.com/fly-book/p/11623995.html
时间: 2024-11-06 03:35:55