每日刷题(122)
合数个数
题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
C++代码
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
for(int i = 2; i * i <= n; i++)
{
if(n % i == 0)
{
return false;
}
}
return true;
}
int main()
{
int ans = 2;
for(int i = 8; i <= 2020; i++)
{
if(!isPrime(i))
{
// cout << i << " ";
ans++;
}
}
// cout << endl;
cout << ans << endl;
return 0;
}
所以答案是1713