Java 中某数阶乘的约数
下面是一个 Java 程序,用于查找某个数阶乘的约数。
程序
import java.util.Scanner;
public class DivisorsOfFactorial {
public static long fact(int i) {
if(i <= 1) {
return 1;
}
return i * fact(i - 1);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the n value :");
int n = sc.nextInt();
int result = 0;
long fact = fact(n);
for (int i = 1; i<= fact; i++) {
if (fact%i == 0) {
result = result+i;
}
}
System.out.println(result);
}
}输出
Enter the n value : 4 60
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP