6 solutions
-
1
刚才看到个 3ms 的,哈哈。我还 2 ms 呢。
#include <bits/stdc++.h> #include <iostream> #include <cmath> using namespace std; const int maxN = 1e6 + 5; int prime[maxN]; bool vis13[maxN];// 素数表 void getPrime() { memset(vis13, true, sizeof(vis13)); vis13[0] = vis13[1] = false; for (int i = 2; i <= maxN / i; ++i) { if (vis13[i]) { prime[++prime[0]] = i; } for (int j = 1; j <= prime[0] && i * prime[j] <= maxN; ++j) { vis13[i * prime[j]] = false; if (i % prime[j] == 0) { break; } } } } int FindOneNum(unsigned int n) { int count = 0; while (n) { n &= n - 1; //将n与n-1异或赋予n count++; } return count; } int main(void) { getPrime(); int l, r; cin >> l >> r; int ans = 0; for (int i = l; l <= r; ++l) { int temp = FindOneNum(l); if (vis13[temp]) { ans++; } } cout << ans << endl; return 0; }
这道题 其实 解出来就行了,ms 什么的 不重要,就是 新手训练而已。
Information
- ID
- 24
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 329
- Accepted
- 99
- Uploaded By