1 条题解

  • 0
    @ 2025-07-25 14:21:04
    #include <bits/stdc++.h>
    
    #define out(x) cout << #x << '=' << (x) << endl
    #define out2(x, y) cout << #x << '=' << (x) << ',' << #y << '=' << (y) << endl 
    #define no do { cout << "No" << endl; return; } while(0)
    #define yes do { cout << "Yes" << endl; return; } while (0)
    #define lowbit(x) ((x) & -(x))
    
    using namespace std;
    
    using ll = long long;
    
    const ll inf = 0x3f3f3f3f3f3f3f3fLL;
    const int infi = 0x3f3f3f3f;
    
    template<typename T> ostream & operator << (ostream &out,const set<T>&obj){out<<"set(";for(auto it=obj.begin();it!=obj.end();it++) out<<(it==obj.begin()?"":", ")<<*it;out<<")";return out;}
    template<typename T1,typename T2> ostream & operator << (ostream &out,const map<T1,T2>&obj){out<<"map(";for(auto it=obj.begin();it!=obj.end();it++) out<<(it==obj.begin()?"":", ")<<it->first<<": "<<it->second;out<<")";return out;}
    template<typename T1,typename T2> ostream & operator << (ostream &out,const pair<T1,T2>&obj){out<<"<"<<obj.first<<", "<<obj.second<<">";return out;}
    template<typename T> ostream & operator << (ostream &out,const vector<T>&obj){out<<"vector(";for(auto it=obj.begin();it!=obj.end();it++) out<<(it==obj.begin()?"":", ")<<*it;out<<")";return out;}
    
    
    void solve() {
        int n;
        cin >> n;
        const int h = n * 2;
        vector<int> minfac(h + 1), primes;
        for (int i = 2; i <= h; i++) {
            if (!minfac[i]) {
                minfac[i] = i;
                primes.push_back(i);
            }
            for (int p : primes) {
                int t = i * p;
                if (t > h) break;
                minfac[t] = p;
                if (p == minfac[i]) break;
            }
        }
        vector<int> ans(n + 1, infi);
        auto calc_fact = [&](int i) -> void {
            unordered_map<int, int> cnt;
            int left = i, right = i + 1;
            while (left > 1) cnt[minfac[left]]++, left /= minfac[left];
            while (right > 1) cnt[minfac[right]]++, right /= minfac[right];
            cnt[2]--;
            
            vector<int> fact = {1};
            for (auto [k, v] : cnt) {
                int now = 0;
                for (int i = 1; i <= v; i++) {
                    int high = fact.size();
                    for (int j = now; j < high; j++) {
                        if (1LL * fact[j] * k <= n) fact.push_back(fact[j] * k);
                    }
                    now = high;
                }
            }
            for (int d : fact) ans[d] = min(ans[d], i);
        };
        for (int i = 1; i < n * 2; i++) calc_fact(i);
        
        ll res = 0;
        for (int i = 1; i <= n; i++) res += ans[i];
        
        cout << res << endl;
    }
    
    int main(void) {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        int t = 1;
        //cin >> t;
        
        while (t--) {
            solve(); 
        }
    }
    
  • 1

信息

ID
1007
难度
9
分类
(无)
标签
递交数
10
已通过
1
通过率
10%
上传者