LightOJ 1336 Sigma Function

题目链接:LightOJ 1336 Sigma Function

题目大意:
([1,n])内所有因数和为偶数的数的个数。

题解:
打表了一下200以内因数和为奇数的数:

1 2 4 8 9 16 18 25 32 36 49 50 64 72 81 98 100

可以看出这些数是(x^2)或者(2 imes x^2),所以减去这些数就可以了。

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int t;
    long long n;
    cin >> t;
    for (int i = 1; i <= t; ++i) {
        cin >> n;
        long long x = sqrt(n);
        long long y = sqrt(n/2);
        cout << "Case " << i << ": " << n - x - y << endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/IzumiSagiri/p/14296031.html