public class SuperFactories { public static int lastWithUnZero = 3;// 便捷的输出测试,从几个回。为了找到一个非零元素迄今 public static void main(String[] args) { int[] factories_10000 = new int[35660];// 用数组装下阶乘的每一位 // 5的阶乘为120 factories_10000[2] = 1; factories_10000[1] = 2; // 从6的阶乘開始 for (int i = 6; i <= 10000; i++) {// 10000的阶乘 // n! = n*(n-1)!;阶乘运算 for (int j = 0; j <= lastWithUnZero; j++) {// factories_10000[j] *= i; } // 进位 for (int j = 0; j <= lastWithUnZero; j++) {// if (factories_10000[j] > 9) { factories_10000[j + 1] += factories_10000[j] / 10; factories_10000[j] %= 10; } } if (factories_10000[lastWithUnZero + 1] > 9) { int temp = lastWithUnZero + 1; while (factories_10000[temp] > 9) { factories_10000[temp +1] += factories_10000[temp] / 10; factories_10000[temp++] %= 10; } } // lastWithUnZero 从后面数。找到一个非零元素为止 for (int j = factories_10000.length - 1; j > 0; j--) { if (factories_10000[j] != 0) { lastWithUnZero = j; break; } } } for (int i = lastWithUnZero; i >= 0; i--) { if(i%100==0){ System.out.println(); } System.out.print(factories_10000[i]); } System.out.println(" -----------" + lastWithUnZero + "++++++++++" + factories_10000[lastWithUnZero]); } }
版权声明:本文博主原创文章,博客,未经同意不得转载。