标签:nbsp math mat include mes bool stream 范围 mic
还是审题没把范围看清楚,没一次AC
题中m和n都表示第几个素数,范围是10000,所以查询的数组中需要的素数量至少10000,所以需要计算大概2~120000的整数才能查到10000个素数
#include <iostream> #include <cmath> #include <vector> using namespace std; bool prime(int x) { for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) return false; } return true; } int main() { vector<int> num; for (int i = 2; i < 150000; i++) { if (prime(i)) num.push_back(i); } int m = 0, n = 0; cin >> m >> n; int cnt = 0; for (int i = m - 1; i < n; i++) { cout << num[i]; cnt++; if (cnt != 10 && i != n - 1) cout << ‘ ‘; else { cnt = 0; cout << endl; } } return 0; }
标签:nbsp math mat include mes bool stream 范围 mic
原文地址:https://www.cnblogs.com/moujun1001/p/9350985.html