解题思路:
超暴力 每次删除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 人评分
【矩阵】 (C++代码)浏览:940 |
Minesweeper (C语言描述,蓝桥杯)浏览:1124 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:668 |
矩阵乘方 (C语言代码)浏览:1023 |
1048题解(读入回车问题)浏览:555 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:636 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:740 |
多输入输出练习2 (C语言代码)浏览:1655 |
杨辉三角 (C语言代码)浏览:676 |
分解质因数 (C++代码)浏览:1472 |