L


私信TA

用户名:1302759659

访问量:2145

签 名:

等  级
排  名 854
经  验 3476
参赛次数 0
文章发表 13
年  龄 17
在职情况 学生
学  校 广西英华国际职业学院
专  业 软件技术

  自我简介:

解题思路:

超暴力 每次删除map.value的倍数然后就过了

参考代码:

import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<Integer, Integer> map = new HashMap<>();
		int m = sc.nextInt(), n = sc.nextInt();
		for (int i = 1, j = 1; i <= n; i++) {
			if ((i & 1) == 1) {
				map.put(j++, i);
			}
		}
		int i = 0;
		for (int t = 2; i * 2 <= n && t <= map.size(); t++) {
			i = map.get(t);
			Map<Integer, Integer> map1 = new HashMap<>();
			int p = 1;
			for (int j = 1; p <= n; j++) {
				p = j * i;
				if (map.containsKey(p)) {
					map.remove(p);
				}
			}
			int k = 1;
			for (int x : map.values()) {
				map1.put(k++, x);
			}
			map.clear();
			map.putAll(map1);
		}
		int ans = 0;
		for (int x : map.values()) {
			if (x > m && x < n) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区