快速幂函数优化1~n 的阶乘java实现
时间: 2023-10-27 21:05:06 浏览: 84
JAVA求N的阶乘
public class Main {
public static void main(String[] args) {
int n = 10;
int mod = 1000000007;
long[] factorial = new long[n + 1];
factorial[0] = 1;
for (int i = 1; i <= n; i++) {
factorial[i] = (factorial[i - 1] * i) % mod;
}
System.out.println("Factorial of " + n + " is " + factorial[n]);
}
}
阅读全文