結果

問題 No.2880 Max Sigma Mod
ユーザー tottoripaper
提出日時 2024-09-12 16:36:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 58 ms / 3,000 ms
コード長 1,430 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 201,176 KB
最終ジャッジ日時 2025-02-24 06:46:05
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using ll = std::int64_t;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int N, M;
    std::cin >> N >> M;

    int L = std::max(N, M);
    std::vector<int> spf(L + 1, 0), primes;
    for(int i=2;i<=L;i++){
        if(spf[i] == 0){
            spf[i] = i;
            primes.emplace_back(i);
        }

        for(int p : primes){
            if(p > spf[i] || !(i <= L / p)){break;}
            spf[i * p] = p;
        }
    }

    ll res = 0;
    ll now = 0;
    for(int i=1;i<=N;i++){
        std::vector<std::tuple<int, int>> factors;
        {
            int x = i;
            while(x > 1){
                int p = spf[x];
                int t = 0;
                while(x % p == 0){
                    x /= p;
                    t += 1;
                }
                factors.emplace_back(p, t);
            }
        }

        std::vector<int> divisors{1};
        for(auto &[p, t] : factors){
            int l = divisors.size();
            divisors.resize(l * (t + 1));
            for(int i=l;i<l*(t+1);i++){
                divisors[i] = divisors[i - l] * p;
            }
        }

        int count = 0;
        for(int d : divisors){
            if(d <= M){
                now -= d - 1;
                count += 1;
            }
        }
        now += M - count;
        res = std::max(res, now);
    }

    std::cout << res << std::endl;
}
0