浅尝辄止

浅尝辄止

Problem:

给定一个正整数n,求(sum_{i=1}^n{[frac{n}{i}]})。式中[x]为向下取整。

答案可能很大,输出答案对998244353取模后的值。

Example:

Input

5

Output

10

Input

10

Output

27

Solution:

整数分块求解

整数分块:https://www.cnblogs.com/peng-ym/p/8661118.html

Code:

class Solution {
public:
    /**
     * 
     * @param n long长整型 
     * @return int整型
     */
    int work(long long n) {
        // write code here
        long long ans=0;
        const long long mod=998244353;
        for(long long l=1,r;l<=n;l=r+1){
            r=n/(n/l);
            ans=(ans+(r-l+1)*(n/l))%mod;
        }
        return ans;
    }
};
原文地址:https://www.cnblogs.com/LeafLove/p/13339088.html