当前位置: 代码迷 >> 综合 >> HDOJ 1406 完数
  详细解决方案

HDOJ 1406 完数

热度:60   发布时间:2023-10-21 19:21:11.0

HDACM 1406

直接打表解决

import java.util.Scanner;public class Main{
    public static void main(String[] args) {boolean finish[] = new boolean[10000];for (int i = 1; i < finish.length; i++) {int sum = 1;for (int j = 2; j*j <= i; j++) {if (i%j==0) {sum += j+i/j;}}if (sum == i) {finish[i] = true;}}Scanner sc = new Scanner(System.in);int n = sc.nextInt();while (n-->0) {int a = sc.nextInt();int b = sc.nextInt();int count = 0;for (int i = a>b?b:a; i <= (a>b?a:b); i++) {if (finish[i]) {count++;}}System.out.println(count);}sc.close();}
}