1013 数素数 (20 分)
#include <iostream> #include <cmath> using namespace std; int main() { int m, n, i = 2, cnt = 0; bool isnum; cin >> m >> n; while (cnt != n) { isnum = true; for (int j = 2; j <= sqrt(i); j++) { if (i % j == 0) { isnum = false; break; } } if (isnum) { // 学会巧妙的设置逻辑变量,可以解决很多关于输出的坑; cnt++; if (cnt >= m && cnt < n && (cnt - m + 1) % 10 != 0) cout << i << ' '; if (cnt >= m && cnt < n && (cnt - m + 1) % 10 == 0) cout << i << endl; if (cnt == n) cout << i; } i++; } cout << endl; return 0; }