HDOJ 2521 反素数

来源:互联网 发布:淘宝网狗狗 编辑:程序博客网 时间:2024/05/22 14:10

HDACM 2521

import java.util.Scanner;public class Main{    public static void main(String[] args) {        int num[] = new int[5001];        for (int i = 1; i < num.length; i++) {            for (int j = i; j < num.length; j++) {                if (j%i==0) {                    num[j]++;                }            }        }        Scanner sc = new Scanner(System.in);        int n = sc.nextInt();        while (n-- > 0) {            int a = sc.nextInt();            int b = sc.nextInt();            int max = num[a];            int ans = a;            for (int i = a+1; i <= b; i++) {                if (num[i]>max) {                    max = num[i];                    ans = i;                }            }            System.out.println(ans);        }        sc.close();    }}
原创粉丝点击