等比数列三角形题解

实现思路

20220428103007

20220428103151

20220428103737

代码实现

/*
 * @Description: 电影和人生不一样,电影太仁慈了,人生太辛苦了
 * @CSDN: https://blog.csdn.net/godhandsjoker?spm=1000.2115.3001.5343
 * @Github: https://github.com/godhandsjoker
 * @QQ: 3124406837
 * @Author: godhands
 * @LastEditTime: 2022-04-28 10:42:09
 */
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n, res = 0;
    double maxk = (1 + sqrt(5)) / 2;
    cin >> n;
    for (int i = 1; i <= n / i; i++) {
        for (int j = i; j <= i * maxk; j++) {
            if (__gcd(i, j) == 1) res += n / j / j;
        }
    }
    cout << res << "\n";
}
signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    solve();
    return 0;
}