zoukankan      html  css  js  c++  java
  • UVa 11526

    这道题学校里的班级程序设计对抗赛决赛中就有这题,当时貌似只有一个人A出来,一头雾水,不知如何下手。其实现在看看AC的思路,当时还是飘出过来的,就是没有信心,按照这个思路写下去。

    思路就是找到所有n/i结果相同的区间[i, j],这样就省出不少时间了,不然会超时。

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long LL;
    inline LL H(LL n)
    {
        LL res = 0;
        for(LL i = 1, j; i <= n; i = j + 1){
            j = n / (n / i);
            res += (j - i + 1) * (n / i);
        }
        return res;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        int T; cin >> T;
        while(T--){
            LL n; cin >> n;
            cout << H(n) << endl;
        }
        return 0;
    }



  • 相关阅读:
    原型污染
    C#之抛异常
    为什么['1', '7', '11'].map(parseInt) returns [1, NaN, 3]?
    Linux
    Linux
    Linux
    Linux
    Linux
    Linux
    其他
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312718.html
Copyright © 2011-2022 走看看