Problem:


Score : 400 points

Problem Statement

Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten.
He remembers that the remainder of a divided by b was greater than or equal to K.
Find the number of possible pairs that he may have had.

Constraints

1 \leq N \leq 10^5

0 \leq K \leq N-1

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of possible pairs that he may have had.

Sample Input 1

5 2

Sample Output 1

7

There are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).

Sample Input 2

10 0

Sample Output 2

100

Sample Input 3

31415 9265

Sample Output 3

287927211



Sample input:
5 2


Sample output:
7

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
if(k==0):
  print(n*n)
  quit()
ans=(n-k+1)*(n-k)//2
for i in range(k+1,n+1):
  ans+=(n//i-1)*(i-k)+max(0,n%i-k+1)
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
if k==0:
    print(n**2)
    import sys
    sys.exit()
    
for b in range(k,n+1):
    r=n//b
    ans+=(b-k)*r
    ans+=max(0,n%b-k+1)

print(ans)

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split(" ")]

s = 0
for b in range(1, n + 1):
    if b > k:
        s += ((n + 1) // b) * (b - k) + max(0, (n + 1) % b - k)
if k == 0:
    s -= n
print(s)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0

for b in range(1, n+1):
    if b <= k:
        continue
    ans += (b-k)*(n//b)
    if n%b >= k:
        if k != 0:
            ans += n%b - k + 1
        else:
            ans += n%b - k
print(ans)

Submission status: Accepted

Solution code:
n, k = [int(item) for item in input().split()]

ans = 0
for b in range(1,n+1):
  if b <= k:
    continue
  ans += (b - k) * (n // b)
  if n % b >= k:
    if k != 0:
      ans += n % b - k + 1
    else:
      ans += n % b - k
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
for i in range(k+1,n+1):
        ans += int(n/i)*(i-k) + max(n%i-k+1,0)
print(ans-n if k == 0 else ans)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys
 
 
n,k = map(int, input().split())
 
ans = 0
for b in range(k+1,n+1):
  ans += (n+1)//b*(b-k)+max(0,(n+1)%b-k)
if k == 0:
  ans = n**2
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

res = 0
for b in range(k+1,n):
    kk = b-k
    
    r = n//b
    kkk = n%b
    if r > 0:
        res += kk*r
    if k == 0:
        res += kkk
    elif kkk>=k:
        res += kkk-k+1
res += n-k
print(res)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

count = 0
for i in range(K + 1, N + 1):
    if K == 0:
        count += N
    else:
        a = (i - K) * (N // i)
        b = 0
        if N % i >= K:
            b = N % i - K + 1
        count += a + b
print(count)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

ans = 0
if K == 0:
    ans = N ** 2
else:
    for b in range(K + 1, N + 1):
        q, r = N // b, N % b
        ans += q * (b - K) + max(0, r + 1 - K)
        
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

if K == 0:
    print(N*N)
    exit()

ans = 0
for b in range(1,N+1):
    ans += max(b-K,0)*(N // b) + max(N%b-K+1,0)
print(ans)

Submission status: Accepted

Solution code:
# ABC090C 3/18
#import numpy as np
#import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def zeros2(n, m): return [zeros(m)]*n # obsoleted zeros((n, m))で代替
def getIntLines(n): return [int(input()) for i in range(n)]
def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat
class Debug():
    def __init__(self):
        self.debug = True

    def off(self):
        self.debug = False

    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N, K = getIntList()
    d.dmp((N, K),'N,K')
    count = 0
    for b in range(K+1, N+1):
        q = N // b 
        r = N % b
        d.dmp((b, q, r),'b * q + r')
        count += q*(b-K)
        d.dmp((count),'count 1')
        if r > 0:
            if K == 0:
                count += r
            else:
                count += max(0, r-K+1)
        d.dmp((count),'count 2')
    d.dmp((count),'count')
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == list and ans[0] == 'col':
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
n, k = map(int, input().split())

if k == 0:
    print(n**2)
    exit()

ans = 0
for i in range(k+1, n+1):
    ans += (n//i)*(i-k)
    r = n%i
    ans += max(r-k+1, 0)
print(ans)

Submission status: Accepted

Solution code:
def remainder_reminder(N: int, K: int) -> int:
    if K == 0:
        return N * N

    count = 0
    for b in range(K + 1, N + 1):
        p, r = N // b, N % b
        count += p * max(0, b - K) + max(0, r - K + 1)
    return count


if __name__ == "__main__":
    N, K = map(int, input().split())
    ans = remainder_reminder(N, K)
    print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())


ans = 0
for b in range(1, N + 1):
    ans += (N + 1) // b * max(0, b - K)
    ans += max(0, (N + 1) % b - K)

if K == 0:
    ans -= N
print(ans)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
N = a[0]
K = a[1]
ans = 0
for i in range(K+1, N+1):
    #a%i>=kとなるパターン数
    ans += (N // i)*(i - K) #p*i<= x < (p+1)i の中にはi-K個だけあまりがK以上のものが存在
    ans += max(0, (N % i) - max(0,(K-1))) #iの倍数までは判定が終了。よって判定すべきなのはpi+1, pi+2,..., pi+(N%i)
print(str(ans))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = sum(
    (b - K) * ((N - K) // b) + (N % b - K + 1 if N % b >= K else b - K)
    for b in range(K + 1, N + 1)
) if K > 0 else N**2
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc090/tasks/arc091_b

import itertools
import collections
import bisect


def main():
    N, K = map(int, input().split())
    ans = 0
    for b in range(K+1, N+1):
        p = N // b
        r = N - b * p
        tmp = p * (b - K) + (max(0, r - K + 1) if K != 0 else max(0, r - K))  # 該当する部分をまとめて計算する
        # print("b = {}, c = {}, p = {}, tmp = {}".format(b, b - K, p, tmp))
        ans += tmp

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc090/tasks/arc091_b

import itertools
import collections
import bisect


def main():
    N, K = map(int, input().split())
    ans = 0
    for b in range(K+1, N+1):
        p = N // b
        r = N - b * p
        tmp = p * (b - K) + max(0, r - K + 1)
        # print("b = {}, c = {}, p = {}, tmp = {}".format(b, b - K, p, tmp))
        ans += tmp

    if K == 0:
        ans -= N

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

n, k = map(int, input().split())


ans = 0

# N = pb + r

for b in range(k+1,n+1):
    p = n//b
    r = n%b
    ans += p * max(0,b-k) + max(0, r-k+1)


if k==0:
    ans -= n

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    ans = 0
    for b in range(1, N+1):
        if K < b:
            tmp = (b-K)*(N//b) + max(N % b - max(K-1, 0), 0)
            ans += tmp
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = 0
    if K == 0:
        print(N * N)
        return 0
    for i in range(1, N+1):
        if i <= K:
            continue
        if N % i < K:
            ans += (N // i) * (i - K)
        else:
            ans += (N // i ) * (i - K) + (N % i - K + 1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#D
n,k = map(int,input().split())
s = 0
for b in range(k+1,n+1):
    s += n//b*(b-k) + max(n%b-max(k-1,0),0)
print(s)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

ans = 0
if k == 0 :
    print(n*n)
else:
    for b in range(k+1,n+1):
        la = int((n+1)/b)
        ans += (la)*(b-k)
        if  (la*b+k) <= n:
            ans += n-(la*b+ k) + 1

    print(ans)

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = map(int, input().split())
ans = 0

if K == 0:
    ans = N*N
else:
    for b in range(K+1, N+1):
        a = (N)//b*(b-K)+max(0, (N-N//b*b)-K+1)
        ans += a
print(ans)

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N,K=rl()
a,b=0,0
ans=0
if K==0:
    ans = N*N
else:
    for b in range(K+1,N+1):
        n = N%b
        ans += b-K
        if n < K:
            ans +=(N//b-1)*(b-K)
        elif K<=n and n<b:
            ans += N//b*(b-K) - (b-n-1)



print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ret = 0
for b in range(1, n+1):
    if b > k:
        ret += n//b * (b-k) + max(0, n % b - k + 1)
if k == 0:
    ret = n * n
print(ret)

Submission status: Accepted

Solution code:
# a ÷ bを考える。bが固定され、aが推移していくことを考えると、余りは0, 1, 2, ...b-1が繰り返される。
# 例 a, b <= 5の場合
# b=1でaが推移していく場合 ：a=0で余り0, a=1で余り0, a=2で余り0, a=3で余り0, a=4で余り0, a=5で余り0
# b=2でaが推移していく場合 ：a=0で余り0, a=1で余り1, a=2で余り0, a=3で余り1, a=4で余り0, a=5で余り1
# b=3でaが推移していく場合 ：a=0で余り0, a=1で余り1, a=2で余り2, a=3で余り0, a=4で余り1, a=5で余り2
# b=4でaが推移していく場合 ：a=0で余り0, a=1で余り1, a=2で余り2, a=3で余り3, a=4で余り0, a=5で余り1
# b=5でaが推移していく場合 ：a=0で余り0, a=1で余り1, a=2で余り2, a=3で余り3, a=4で余り4, a=5で余り0
# 上記より、bをループさせれば「ある値以上の余りがいくつあるか」を求められる？
# 上記の右側の部分の合計をO(1)で求めたい


n, k = map(int, input().split())

if k == 0:
    print(n*n)
    exit()
res = 0
# bをnumとして考える
for num in range(k, n + 1):
    # numに対して余りのループがいくつあるか考える
    group = n // num
    mod = n % num

    # 余りの最大値はnum-1
    # group×「1グループ内にどれだけ余りがkを超える数があるか」 + 「1グループに満たないもの」
    res += group * max(0, num - k) + max(mod - k+1, 0)
print(res)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
def main():
  for a in range(K+1, N+1):
    s = (a-K)*(N//a)+max(N%a-K, 0)
    s = s-1 if K==0 else s
    s = s+1 if N%a>=K else s
    yield s
print(sum(main()))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

ans = 0

for i in range(k+1,n+1):
    d = (n+1) // i
    m = (n+1) % i
    p = d*(i-k) + max(0,m-k)
    #print(p)
    ans += p
if k==0 :
    ans -= n

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
if K == 0:
    print(N**2)
    exit()
ans = 0
for b in range(K+1,N+1):
    i1 = 0; i2= 0
    Q = (N-K)//b
    i1 = Q*(b-K) 
    left = K; right = min(N-b*Q,b-1)
    #print("{}<=r<={}".format(left,right))
    i2 = max(right - left + 1,0)
    ans += i1 + i2
    #print(i1,i2)
print(ans)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))

if K == 0:
  print(N * N)
  exit()
  
Ans = 0
for i in range(K + 1, N + 1):
  Ans += (i - K) * ((N + 1) // i) + max(((N + 1) %  i) - K, 0)
  
print(Ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
if k==0:
    ans=n**2
else:
    for b in range(k+1,n+1):
        p=n//b
        q=n%b
        tmp=(b-k)*p+max(0,q-k+1)
        ans+=tmp
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
ans = 0
for b in range(1,N+1):
    ans += max(0,b-K)*(N//b) + max(0,(N%b)-K+1)
if K == 0:
    ans -= N
print(ans)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))

ans = 0
if k == 0:
    ans = n * n
else:
    for b in range(k + 1, n + 1):
        ans += n // b * (b - k)
        ans += max(0, (n - (n // b * b)) - k + 1)

print(ans)

Submission status: Accepted

Solution code:

n,k = map(int,input().split())
ans = 0
for b in range(k+1,n+1):
    case = (n//b)*(b-k)
    if n%b >=k:
        if k==0:
            case += n%b
        else:
            case += n%b-k+1

    ans += case
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
  ans += max(i-k,0)*(n//i)+max(n%i-k+1,0)
print(ans if k!=0 else ans-n)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

cnt = 0
for i in range(K+1,N+1): # i:割る数
    cnt += (i-K)*(N//i)
    if K != 0:
        cnt += max(N%i-K+1,0)
    else:
        cnt += max(N%i-K,0)
    # print(cnt)
print(cnt)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())

ans=0
for b in range(K+1,N+1):
    # p*b-1<N<=(p+1)*b and p*b+K+q<=N<p*b+K+q+1
    p = (N+1)//b
    q = N-p*b-K

    ans+=p*(b-K)
    if q>=0:
        ans+=q+1
    if K==0:
        ans-=1

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())

if k == 0:
    print(n**2)
else:
    total = 0
    for i in range(k+1,n+1):
        d,m = divmod(n,i)
        
        if (i-k) > 0:
            total += d*(i-k)
        if (m-k+1) > 0:
            total += m-k+1

    print(total)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math

def main():
    s = input().split()
    N, K = int(s[0]), int(s[1])

    c = 0
    for b in range(K + 1, N + 1):
        db, mb = int(N / b), N % b
        if mb == 0 or mb < K:
            c += (b - K) * db
        else:
            c += (b - K) * db
            if K == 0:
                c += N - (b * db + K)
            else:
                c += N - (b * db + K) + 1
#        print(c)

    print(c)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

ans = 0
if k == 0:
    ans = n ** 2
else:
    for b in range(k+1, n+1):
        q = n // b
        r = n % b
        ans += q * (b-k) + max(0, r-k+1)
    
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0

if k == 0:
    ans = n ** 2
else:
    for b in range(k + 1, n + 1):
        q, r = n // b, n % b
        ans += (b - k) * q + max(r + 1 - k, 0)
    
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
ans = 0
for mod in range(k+1,n+1):
  ans += (mod - k) * (n // mod)
  if n % mod >= k:
    ans += n % mod - k + 1 
    if k == 0:
      ans -= 1
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

ans = 0
for b in range(K + 1, N + 1):
    ans += (b - K) * (N // b)
    ans += max(0, N % b - K + 1)
    
if K == 0:
    ans -= N

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
bit=0 if K==0 else 1
for b in range(K+1,N+1):
  ans+=N//b*(b-K)+max(0,N%b-K+bit)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N, K = map(int, input().split())

# 余り0以上は全ての組
if K == 0:
    print(N*N)
    exit()

ans = 0
# 割られる数でループ
for i in range(1, N+1):
    # 割られる数がK以下ならmodしてKはあり得ない
    if i <= K:
        continue
    # 確実に入る分
    ans += N // i * (i-K)
    # 最後の分を調整
    ans += max(N % i - K + 1, 0)
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
count = 0

if k == 0:
    count += n * n

else:
    for b in range(k + 1, n + 1):
        q, r = n // b, n % b
        count += q * (b - k) + max((r + 1 - k), 0)
        
print(count)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
ans = 0

if k == 0:
    ans = n ** 2
else:
    for b in range(k + 1, n + 1):
        q, r = n // b, n % b
        ans += q * (b - k) + max((r - k + 1), 0)
            
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
s = 0
for b in range(k+1,n+1):
  s += n//b*(b-k) + max(n%b-max(k-1,0),0)
print(s)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
#print(n,k)
ans=0
if k==0:
    ans=n**2
else:
    for i in range(k+1,n+1):
        a,b=n//i,n%i
        if b<k:
            ans+=a*(i-k)
        else:
            ans+=a*(i-k)+(b-k+1)
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split());print(N*(N+(K!=0))-sum(min(b,K,N-a+1)for b in range(1,N+1)for a in range(0,N+1,b)))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
print(N * (N + (K != 0)) - sum(min(b, K, N - a + 1) for b in range(1, N + 1) for a in range(0, N + 1, b) ))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

ans = N * (N + (K != 0))
ans -= sum(min(b, K, N - a + 1) for b in range(1, N + 1) for a in range(0, N + 1, b) )
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

ans = N * (N + (K != 0))
for b in range(1, N + 1):
    for a_ in range(0, N + 1, b):
        ans -= min(b, K, N - a_ + 1)

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K == 0:
    print(N * N)
    exit()

ans = N * (N + 1)
for b in range(1, N + 1):
    for a_ in range(0, N + 1, b):
        ans -= min(b, K, N - a_ + 1)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())

ans = 0
for b in reversed(range(1, N+1)):
    s = N//b
    tmp = ( max([0,b-K]))* s
    tmp2 = max([0,N - b * s - max([0,(K-1)]) ]) 
    ans += tmp + tmp2

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for b in range(K+1,N+1):
  if N-b*(N//b)>=K:
    ans+=(N//b)*(b-K)+(N-b*(N//b)-K+1)
    if K==0:
      ans-=1
  else:
    ans+=(N//b)*(b-K)
    if K==0:
      ans-=1
print(ans)

Submission status: Accepted

Solution code:
def ans(N, M):
    if M == 0: return(N * N)
    cnt = 0
    for i in range(1,N+1):
        p, q = divmod(N,i)
        cnt += p * max(i-M,0) + max((q-M)+1,0)
    return(cnt)

N, M = list(map(int, input().split()))
print(ans(N, M))

Submission status: Accepted

Solution code:
def ans(N, M):
    if M == 0: return(N * N)
    ans = 0
    for i in range(1,N+1):
        p, q = divmod(N,i)
        ans += p * max(i-M,0) + max((q-M)+1,0)
    return(ans)

N, M = list(map(int, input().split()))
print(ans(N, M))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

res = 0

if K == 0:
    print(N ** 2)
else:
    for b in range(K + 1, N + 1):
        res += N//b * (b - K)
        if N % b >= K:
            res += N % b - K + 1
    
    print(res)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

if k == 0:
  print(n**2)
  exit()
    
ans = 0
for b in range(k+1, n+1):
  p = n//b
  r = n%b
  
  ans += p*(b-k)
  ans += max(0, r-k+1)
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

ans = 0
for b in range(1, N + 1):
    x = N // b
    c = N % b
    if K != 0:
        ans += x * max(0, b - K) + max(0, c - K + 1)
    else:
        ans += x * max(0, b - K) + c

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())

ans=0
for i in range(1,n-k+1):
    ans+=(n//(k+i))*i
    ans+=max([0,n%(k+i)-k+1])
if(k==0):
    ans-=n
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
count = 0
for b in range(1, n + 1):
    if k < b:
    #a < bを考える
        if k != 0:
            count += b - k
        else:
            count += b - 1
    # a > bを考える
        p = n // b - 1
        q = n % b - k + 1 if n % b - k + 1 > 0 else 0
        count += p * (b - k) + q
print(count)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

ans = 0
for b in range(k+1, n+1):
    p = n // b
    q = n % b
    ans += (b-k)*p
    if q >= k and k > 0:
        ans += q-k+1
    elif q >= k and k == 0:
        ans += q

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for i in range(1, N+1):
    ans += N//i * max(0, i - K) + max(0, N % i - K + 1)
if K == 0:
    ans -= N
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
if K == 0:
    print(N*N)
    exit()

ans = 0
for b in range(K+1,N+1):
    d,m = divmod(N,b)
    ans += (b-K)*d + max(0, m+1-K)
print(ans)

Submission status: Accepted

Solution code:
import sys

N,K=map(int,input().split())

#a<=N,b<=N
#a%b>=K
#b>=K+1

#b=4のとき,
#a%b=2,3
#N//b*(b-K)+max(0,N%b-K+1)

if K==0:
    print(N**2)
    sys.exit()

ANS=0
for b in range(K+1,N+1):
    ANS+=N//b*(b-K)+max(0,N%b-K+1)

    #print(b,N//b*(b-K),max(0,N%b-K+1))

print(ANS)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
num = 0
if K == 0:
    print(N * N)
else:
    for b in range(1, N + 1):
        p, r = N // b, N % b
        num += p * max(0, b - K)
        num += max(0, r - K + 1)

    print(num)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

ans = 0
for b in range(1, n + 1):
    # n = pb + r
    p, r = divmod(n, b)
    ans += p * max(b - k, 0) + max(r - k + 1, 0)
    if k == 0:
        ans -= 1

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for b in range(1, N + 1):
    ans += (N // b) * max(0, b - K) + max(0, (N % b) - K + 1)
print(ans - (N if K == 0 else 0))

Submission status: Accepted

Solution code:
"""
r>=kのものを調べる
bがN以下、aがb以下でfor loop
K

for loopを1重にしたい->0~Nまで動かすとどうなるか考える
bを固定する
N=b*p+r (r:あまり)

あるbについてaを0~Nまで動かすと、a%b=0,1,2,...,b-1,0,...
(0~b-1)がp回繰り返され、最後に0,1,...,r-1,rがつけ加わった形になる

あまりの数は、(b-K)*p + (r-K+1)
"""
N, K = map(int, input().split())

ans = 0

for b in range(1,N+1): #1~Nまで
  r = N%b
  p = (N-r)//b
  ans += max(0,(b-K)*p) + max(0,(r-K+1))

#a=0のときは、K=0で問題になりansからNを引けば良い
if K==0:
  ans -=N

print(ans)

Submission status: Accepted

Solution code:
ans = 0
N,K = map(int,input().split())
for b in range(K+1,N+1):
    x1,y1 = divmod(N-K,b)
    x2,y2 = divmod(N-b+1,b)
    if x1==x2:
        ans += (x1+1)*(y1-y2+1)
    else:
        ans += (x1+1)*(y1+1) + (x2+1)*(b-y2)+b*(x1+x2+2)*(x1-x2-1)//2
if K == 0:
    print(N*N)
else:
    print(ans)

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))

if k == 0:
    print(n**2)
    exit()
    
ans = 0
for b in range(k+1, n+1):
    ans_bk = (n-k)//b+1
    ans_b = ans_bk*(b-k)
    
    mod_k_max = ((n-k)//b)*b+k
    if n-mod_k_max+1 < b-k:
        ans_b -= ((b-k) - (n-mod_k_max+1))
    # print(ans_b)
    ans += ans_b
            
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int, input().split())
A=[0]*(N+1)
count=0
for i in range(1, N+1):
	A[i]=int(N/i)
	
for i in range(K+1,N+1):
	count += A[i]*(i-K)
	if N-A[i]*i >= K :
		if K==0:
			count += N-A[i]*i
		else:
			count += N-A[i]*i-K+1

print(count)

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())

def solve():
    if k == 0:
        return n ** 2
    
    ans = 0
    for b in range(k + 1, n + 1):
        mmin = (n - b) // b + 1
        mmax = (n - k) // b
        ans += (b - k) * mmin
        ans += (n - k + 1) * (mmax - mmin + 1) - b * (mmax * (mmax + 1) - (mmin - 1) * mmin) // 2
    return ans

print(solve())

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
if k == 0:
    print(n*n)
else:
    for i in range(n-k):
        ans += n // (i + k + 1) * (i + 1)
        if n % (i + k + 1) >= k:
            ans += n % (i+k+1)-k+1
    print(ans)

Submission status: Accepted

Solution code:
N, K = [int(x) for x in input().split()]
c = 0
if K == 0:
    c = -1
ans = 0
for b in range(K+1, N+1):
    ans += N//b*(b-K)+max(0,(N-N//b*b-K+1)) + c

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
if k == 0:
    print(n * n)
    exit()
for b in range(k + 1, n + 1):
    p = n // b
    r = n % b
    ans += (b - k) * p
    if r >= k:
        ans += r + 1 - k
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

ans = 0
for i in range(K + 1, N + 1):
    # print(i, N // i, N // i * (i - K))
    # print(i)
    tmp = N // i
    ans += tmp * (i - K)
    # print("a", tmp * (i - K))
    if(N % i >= K):
        ans += N % i - K + int(K > 0)
        # print("b", N % i - K + 1)

print(ans)

Submission status: Accepted

Solution code:
N, K = [int(c) for c in input().split()]

if N < K:
    print(0)
elif K == 0:
    print(N**2)
else:
    cnt = 0
    b_min = K+1 if K > 0 else 1
    for b in range(b_min, N+1):
        #print((N//b) * max(0, b-K) + max(0, (N%b)-K+1))
        cnt += (N//b) * (b-K) + max(0, N%b-K+1)

    print(cnt)

Submission status: Accepted

Solution code:
def iin(): return int(input())
def nl(): return list(map(int, input().split()))

n, k = nl()

ans = 0
for b in range(1, n + 1):
    ans += (n // b) * max(0, b - k)
    if k == 0:
        ans -= 1
    ans += max(0, (n % b) - k + 1)
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if K == 0:
    print(N * N)
    exit()
cnt = 0
for b in range(K + 1, N + 1):
    p = N // b
    r = N % b
    cnt += p * (b - K)
    if r >= K:
        cnt += r - K + 1
print(cnt)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if K == 0:
    print(N * N)
    exit()
cnt = 0
for b in range(K + 1, N + 1):
    p, r = divmod(N, b)
    cnt += p * (b - K)
    if r >= K:
        cnt += r - K + 1
print(cnt)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for b in range(1, N + 1):
    p, r = divmod(N, b)
    ans += p * max(0, b - K) + max(0, r - K + 1)
if K == 0:
    ans -= N
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if K == 0:
    print(N * N)
    exit()
cnt = 0
for b in range(K + 1, N + 1):
    p, r = divmod(N, b)
    cnt += p * (b - K) + max(r - K + 1, 0)
print(cnt)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
ans = 0
for k in range(N):
    b = k + 1
    p = int(N//b)
    r = N%b
    ans += p*max(0,b-K) + max(0,r-K+1)
if K == 0:
    ans -= N
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
if K == 0:
    print(N * N)
else:
    for a in range(K + 1, N + 1):
        ans += (N// a) * (a - K) + max(N % a - K + 1, 0)
    print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
if K == 0:
    print(N ** 2)
else:
    for b in range(1, N+1):
        ans += (N // b) * max(0, b - K) + max(0, (N % b) - K + 1)
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,K = inpl()
if K == 0:
	print(N**2)
else:
	ans = 0
	for b in range(K+1,N+1):
		n = N//b #ループ回数
		x = N%b  #末尾
		ans += (b-K)*n + max(0,x-K+1)
	print(ans)

Submission status: Accepted

Solution code:
#encoding utf-8

n, k = map(int, input().split())

count = 0
if k == 0:
    count = n**2
else:
    for i in range(k, n+1):
        count += int(n/i)*(i-k)
        if (n%i-k >= 0):
            count += n%i-k+1
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

def solve(N, K):
    if K == 0:
        return N * N

    ans = 0
    for b in range(1, N + 1):
        now = K
        while K <= b and now <= N:
            ans += min(N, now + (b - K) - 1) - now + 1
            now += b
    return ans

def main():
    N, K = map(int, input().split())

    print(solve(N, K))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
if k == 0:
    ans = n ** 2
else:
    for b in range(1, n + 1):
        if k < b:
            ans += n // b * (b - k)
        if (n % b >= k) and (n % b != 0):
            ans += n % b - k + 1
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())

ans = 0
for b in range(K+1,N+1):
    p = (N+1) // b
    q = (N+1) % b
    
    ans += p*(b-K) + bool(q)*max(0,q-K)
    
if K==0:
    ans -= N
    
print(ans)

Submission status: Accepted

Solution code:

def find_ans(N,K):
    # K==0ならN^2が答え
    if K==0:
        return N**2
    
    # そうでなければK+1～Nについて一般式
    else:
        ans = 0
        for i in range(K+1,N+1):
            ans += (N//i)*(i-K) + max(N%i-(K-1), 0)
            
        return ans
    
N,K = map(int, input().split())
print(find_ans(N,K))

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]

def calc(n, k, b):
    if k == 0:
        return n
    q, r = divmod(n, b)
    s = q * max(0, b-k) + max(0, r-k+1)
    return s


count = 0
b = 1
while b <= n:
    count += calc(n, k, b)
    b += 1

print(count)

Submission status: Accepted

Solution code:
N,K = map( int, input().split())
ans = 0
if K == 0:
    ans = N**2
else:
    for b in range(K+1,N+1):
        ans += ((N+1)//b)*(b-K) + max(0, N - ((N+1)//b)*b-(K -1))
print(int(ans))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
pairs = 0
for b in range(K + 1, N + 1):
  pairs += ((N // b) * (b - K)) + max((N % b) - max(K - 1, 0), 0)
print(pairs)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
pairs = 0
for b in range(K + 1, N + 1):
  pairs += ((N // b) * (b - K)) + ((((N % b) - K + 1) if (N % b) >= K else 0) if K else (N % b))
print(pairs)

Submission status: Accepted

Solution code:
# 解説どおりにやるとK = 0で失敗する? 
def number_of_a(b):
	if K == 0:
		return N
	q, r = divmod(N,b)
	# for each range, we have b-K possible A's
	# in the last range, we have max(0,r-K+1) possible A's.
	s = q * max(0,b-K) + max(0,r-K+1)
	# print((b,q,r,s))
	return s
 
N, K = map(int,input().split())
s = 0; b = 1;
while b <= N:
	s += number_of_a(b)
	b += 1
print(s)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
for b in range(k + 1, n + 1):
    ans += (n // b) * (b - k) + max(0, (n % b - k + 1) if k > 0 else (n % b))
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

count = 0
if K == 0:
    count = N ** 2
else:
    for b in range(1, N + 1):
        d = N // b
        r = N % b
        count += d * max(0, b - K) + max(0, r - K + 1)
print(count)

Submission status: Accepted

Solution code:
def As(b):
	if K==0:
		return N
	q = N//b
	# on each range we have b-K possible A's
	s = (b-K) * q
	if q*b+K <= N:
		s += min((q+1)*b-1,N) - (q*b+K-1)
	return s

N, K = map(int,input().split())
s = 0; b = K+1;
while b <= N:
	s += As(b)
	b += 1
print(s)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = 0
if k == 0:
  print(n ** 2)
else:
  for b in range(k + 1, n + 1):
    ans += (n // b) * (b - k) + max(0, n % b - (k - 1))
  print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
c=0
if k==0:
 print(n**2)
else:
  for b in range(k,n+1):
    p=int(n/b)
    r=n%b
    c+=(b-k)*p
    if r>=k:
      c+=r-k+1
  print(c)