• + 0 comments

    Python 2 Code

    P = 10**9+7
    N = 100000
    for t in xrange(int(raw_input())):
        n = int(raw_input())
        ans = 0
        nn = min(n,N)
        K = 0
        for d in xrange(1,nn+1):
            K = n/d
            ans += K*(K-1)/2*d
            ans += (n%d)*K
        ans %=P
        if nn<n:
            dd = nn+1
            dn = 0
            dnr = 0
            rr = 0
            for i in xrange(1,N+1):
                dn = n/(i+1)
                if dn*(i+1)<n:
                    dn+=1
                if dn>n:
                    dn=n+1
                if dn-1>=dd:
                    ans += (dn-1+dd)*(dn-dd)/2*i
                if dn<dd:
                    dn=dd
                if dn<=n:
                    dnr = n-i*dn
                    if dnr>0:
                        rr = (dnr+i-1)/i
                        ans += (dnr+dnr-(rr-1)*i)*rr/2*i
        print (ans+n)%P