#include <iostream> #include <set> #include <cmath> using namespace std; int main() { int n; cin >> n; int count = 0; for (int i = 1; i <= n; i++) { set<int> factors; for (int j = 1; j <= sqrt(i); j++) { if (i % j == 0) { factors.insert(j); factors.insert(i/j); } } if (factors.size() % 2 == 1) { count++; } } cout << count << endl; return 0; }
#include #include #include using namespace std; int main() { int n; cin >> n; int count = 0; for (int i = 1; i <= n; i++) { set factors; for (int j = 1; j <= sqrt(i); j++) { if (i % j == 0) { factors.insert(j); factors.insert(i/j); } } if (factors.size() % 2 == 1) { count++; } } cout << count << endl; return 0; }
已AC
謝謝