用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 送芒果的祝福语简短
18 送给学长毕业祝福语简短