package net.yk.mlgorithm;/** * factorial * @author administrator * * for larger numbers @param <T> */public class ArraysMul<T> {public static Void main (String[] args) {int[] array = factorial (+);p rintnum (array);} /** * calculates two two-group multiply * @param a * @param b * @return The number represented by the array */public static int[] mul (int a[], int b[]) {int alen = a.length;int blen = b.length;int temp = 0;int len = alen + blen;int t[] = new int[len];for (int i = 0; i <= len - 1; i++) {t[i] = 0;} for (int i = 0; i <= alen - 1; i++) {for (int j = 0; j <= blen - 1; j+ +) {temp = a[i] * b[j];t[j + i] += temp;}} carry operations with a T array greater than 10 carrybit (t); return t;} /** * the number represented by the array, carrying the carry operation for each bit * @param a */static void carrybit (int a[] ) {int len = a.length;int temp;for (int i = 0; i <= len - 2; i++) {temp = a[i];if (temp >= 10) {a[i] = temp % 10;a[i + 1] = a[i + 1] + temp / 10;}}} /** * print Words * @param a */static void printnum (int a[]) {int len = a.length;int f = 0;for (int i = len - 1; i >= 0; i--) {if (a[i] > 0) f = 1;if (f > 0) {system.out.print (A[i]);}} /** * * converts a number to a digital representation * @param n * @return */static int[] dividenumtoarray (int n) {int bit = bits (n); int[] array = new int[bit];int i = 0;do {array[i+ +] = n % 10;n = n / 10;} while (n > 0); return array;} /** * returns the number of bits * @param n * @return */static int bits (int n) {int cnt = 0;while (n > 0) {n = n / 10 ; cnt++;} return cnt;} /** * n factorial * @param n * @return */static int[] factorial ( Int n) {int[] result = {1} ;if (n<0) {system.out.println ("Input error"); Return null;} if (n ==0) { result = new int[0]; result[0] = 1; return Result;} Int bit = bits (n); Int temp[] =&nbsP;new int[bit];for (int i=1;i<=n;i++) {Temp = dividenumtoarray (i); Result = mul ( Temp, result);} Return result;}}
The factorial of a larger integer n, because n is larger than the normal type of the factorial of the expression range, using an array of operations (Java implementation)