用Java查找数字的礼貌
可以表示为正连续整数之和的数字称为礼貌数字。
Ex: 5 = 2+3
用正整数之和表示数字的方式的数量就是该数字的礼貌程度。
Ex: 9 = 4+5 || 2+3+4
算法
得到一个数的素数。
获得大于2的素因子的幂。
将它们加1。
将它们相乘,从结果中减去1。
程序
import java.util.Scanner;
public class PolitenessOfANumber {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int num = sc.nextInt();
int count = 0, result = 1;
for(int i = 2; i< num; i++) {
while(num%i == 0) {
System.out.println(i+" ");
num = num/i;
if(i>2) {
count ++;
}
result = result*(count+1);
}
if(num >2) {
System.out.println(num);
}
System.out.println("Politeness of the given number is : "+(result-1));
}
}
}输出结果
Enter a number 216 2 2 2 3 3 3 Politeness of the given number is : 3
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短