提交时间:2024-11-09 09:52:45
运行 ID: 56071
#include <iostream> using namespace std; bool isPrime(int num) { if (num < 2) return false; for (int i = 2; i * i <= num; i++) { if (num % i == 0) return false; } return true; } int countPrimes(int n) { int count = 0; for (int i = 2; i <= n; i++) { if (isPrime(i)) count++; } return count; } int main() { int n; cin >> n; cout << countPrimes(n) << endl; return 0; }