1 条题解
-
0
C++ :
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 9; int a[N]; int k, p[N]; //p[1] ~ p[k]共k个素数 int main() { a[0] = a[1] = 1; for (int i = 2; i <= 1e7; i ++) { if (!a[i]) p[++ k] = i; for (int j = 1; p[j] <= 1e7 / i; j ++) { a[i * p[j]] = 1; if (i % p[j] == 0) break; } } int n, x, cnt; cin >> n; while (n --) { cnt = 0; cin >> x; if (x <= 3 || x > 1000) { cout << "ERROR" << endl << endl; continue; } for (int i = 2; i <= x; i ++) { if (!a[i]) cnt ++; } if (!cnt) cout << "ERROR" << endl << endl; else cout << cnt << endl << endl; } return 0; }
- 1
信息
- ID
- 2057
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者