题解 | 小红与gcd和sum

小红与gcd和sum

https://www.nowcoder.com/practice/67fe6737ef7447e4ab95bfdbb7f6de6f

萌新

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
void bre(ll a, unordered_map<ll, ll>& mp) {
    mp[1] += a;
    mp[a] += 1;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0){
            mp[i] += a / i;
            if(a/i!=i)
            mp[a/i] += i;
        }
    }
}
int main() {
    int n;
    cin >> n;
    unordered_map<ll, ll> mp;
    vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        bre(a[i], mp);
    }
    ll ma = 0;
    for (auto it : mp) {
        auto [d, r] = it;
        ma = max(ma, d * r * d);
    }

    cout << ma << "\n";
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务