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())

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

Submission status: Accepted

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

Submission status: Accepted

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

print(total)

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, k = input_int_list()
    ans = 0
    if k == 0:
        print(n * n)
        return
    #  bを固定し、aとしてあり得る範囲をO(1)で求める。

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

    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def num_divisors_cnt(n):
    table = [0] * (n + 1)
    
    for i in range(1, n+1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

if k == 0:
    ans = n**2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
ans = 0
for b in range(k+1, n+1):
    val = (b-k) * (n//b) + max(0, (n%b)-k+1)
    if k==0:
        val -= 1
    ans += val
#     print(b,val)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

X=0
for b in range(1,N+1):
    if b<=K:
        X+=N+1
    else:
        q,r=divmod(N,b)
        X+=K*q+min(r+1,K)
print(N*(N+1)-X)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
ans = 0
if k == 0:
    print(n**2)
    exit()
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 i in range(k+1,n+1):
  ans+=n//i*(i-k)
  if n//i*i+k<=n:ans+=n+1-(n//i*i+k)
print([ans,n**2][k==0])

Submission status: Accepted

Solution code:
import sys
n,k = map(int,input().split())
ans = 0
if k == 0:
    print(n**2)
    sys.exit()
for b in range(k+1,n+1):
    ans_per_loop = b - k
    loop, r = divmod(n,b)
    new = ans_per_loop*loop
    if r >= k:
        new += r-k+1
    ans += new
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

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

for i in range(K+1, N+1):
    count += (i - K) * (N // i)
    count += max(0, N - ((N // i) * i) - K + 1)
print(count)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
if K == 0:
    ans = N*N
else:
    ans = 0
    j = 1
    for i in range(K+1, N+1):
        mod = N % i
        x = N//i
        ans += x*j
        if mod>=K:
            ans+=mod-K+1
        j += 1
print(ans)

Submission status: Accepted

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

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

for i in range(k + 1, n + 1):
    # 周期i
    # 0 1 2 3 ... i - 1, 0,
    # 1周期にi - kこk以上

    # 1始まりなのがめんどい
    # 最初1周期だけさせる
    m = n
    m -= i - 1
    ans += i - k

    full = m // i * (i - k)
    amari = m % i  # 周期の途中でnを超える
    ans += full + max(0, amari - k)
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()

ans = 0
for b in range(K+1, N+1):
    cnt = 0
    while b*(cnt+1)<=N:
        ans += b*(cnt+1)-(b*cnt+K)
        cnt += 1
    if K!=0:
        ans += max(0, N-b*cnt-K+1)
    else:
        ans += max(0, N-b*cnt-K)
print(ans)

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())

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

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

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):
    ans += (N//b)*max((b-K),0)

    ans += max(0, 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):
    q, r = divmod(N, b)
    ans += q * (b-K) + max(r - K + 1, 0)
    if K == 0:
        ans -= 1 #a != 0
    #print(ans)

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# bが1-Nまでの場合を考えて、余りがK以上の物を足していく
res = 0

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
ans = 0
if K == 0:
  print(N**2)
  exit()
for b in range(K+1,N+1): #bを一個ずつチェックK+1からNまで
  amari = b-K
  loop = N//b
  nokori = max(N%b+1-K,0)
  temp = loop*amari + nokori
  #print(b,amari,loop,nokori,temp)
  ans += temp
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
if K == 0:
  print(N ** 2)
  exit(0)
res = 0
for i in range(1, N + 1):
  if i <= K: continue
  res += i - K
  for j in range(i, N + 1, i):
    res += min(N + 1, j + i) - min(N + 1, j + K)
print(res)

Submission status: Accepted

Solution code:
# all n integers can be divided into blocks of integers of size i  and in each 
# there will be total i-k integers which has remainder greater than k so we multiply this with no of blocks
# if there is a last block remaining we add all integers with remainder greater than k
def main():
	n , k = map(int , input().split())
	ans = 0
	for i in range(k+1 , n+1):
		ans = ans+(n//i*(i-k))
		if n%i>0:
			if k==0:
				ans = ans+n%i
			else:
				ans =ans +max(0 , n%i-k+1)
	print(ans)
if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    ans = 0
    for i in range(K + 1, N + 1):
        ans += N // i * (i - K)
        if N % i > 0:
            if K == 0:
                ans += N % i
            else:
                ans += max(0, N % i - K + 1)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


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



    
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, K = read_ints()
    answer = 0
    if K == 0:
        return N*N
    for b in range(K+1, N+1):
        answer += (N//b)*(b-K)+max(0, N%b-(K)+1)
    return answer


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()

    # 愚直なやり方で見つけたパターンをb毎の式に落とす
    # for a in range(1, N+1):
    #     print([a % b for b in range(1, N+1)])

    ans = 0
    for b in range(K + 1, N + 1):
        # 繰り返し分
        ans += (b - K) * (N // b)
        # 半端分
        ans += max(N % b - max(K - 1, 0), 0)

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())

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

# b は K 以上
# a は b * c + K <= a < b * (c+1)
ans = 0
for i in range(1, N+1):
    # print(N // i, (i - K), max(N % i - K, 0))
    tmp = (N // i) * max(i - K, 0) + max(N % i + 1 - K, 0)
    ans += tmp

print(ans)

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
ans = 0
if k == 0:
    ans = n**2
else:
    for b in range(k+1, n+1):
        x = n//b
        y = n % b
        ans += (b-k)*x + (y-k+1 if y >= k else 0)
print(ans)

Submission status: Accepted

Solution code:
N,K=list(map(int,input().split()))
if K==0:
   print(N**2)
   exit()
ans=0
for i in range(1,N+1):#割る数
   if i<=K:
      continue
   else:
      ans+=(N//i)*(i-K)
      ans+=N-(N//i)*i-(K-1) if N-(N//i)*i-(K-1)>0 else 0
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
b=[i for i in range(k+1,n+1)]
ans=0
if k==0:
    for i in range(len(b)):
        t=b[i]
        j=t-k
        ii=n//t
        ans+=ii*j
        ans+=max(n-ii*t-k,0)
    print(ans)
    exit()
for i in range(len(b)):
    t=b[i]
    j=t-k
    ii=n//t
    ans+=ii*j
    ans+=max(n-ii*t-k+1,0)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0
for b in range(1, n + 1):
    ans += max(b - k, 0) * (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
for i in range(k+1,n+1):
    x = n//i
    ans += x*(i-k)
    ans += max(0,n%i-max(1,k)+1)
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    ans = 0
    for b in range(K + 1, N + 1):
        q, r = divmod(N, b)
        ans += (b - K) * q
        ans += max(0, min(b - 1, r) - max(1, K) + 1)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
if k==0:
    print(n**2)
    exit()

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

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:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def dd(b, n, k):
	if k==0:
		return n
	if b <= k:
		return 0
	ret = 0
	na = n // b
	ret += na * (b-k)
	
	nb = n % b
	ret += max(nb - k + 1, 0)
	#pa((b,ret))
	return ret

def main():
	#a = int(input())
	n, k = tin()
	#s = input()
	ret = 0
	for b in range(1, n+1):
		ret += dd(b,n, k)
	print(ret)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

# 問題:aをbで割った余りがK以上
# bを固定(これにより、可能性のある余りの値は0,1,...b-1に限られる)して、aの数を数える
# N=pb+rとする
# 余りは、0,1,2,...,b-1のループを(p=0,1,...,p-1)とp回繰り返し、0,1,2,...rで終わる
# p = N//b, r = N%b
# ループ部分はp * max(0,b-K)個、最後の部分はmax(0,r-K+1)個が条件を満たす
# K >= b (ex. 3で割った余りが5以上ですとか言われた時)に0を返すためにmaxを使っている

ans = 0
# bを固定
# bで割って余りがK以上なので、bはK+1からNまでのみ考えても良い
for b in range(1, N + 1):
    p = N // b
    r = N % b
    # K=0だとここでa=0の場合も含んでしまう、a>1という条件なので調整が必要
    # これは各bについて1通りなので最後にN引けば良い
    ans += p * max(0, b - K) + max(0, r - K + 1)
    # print(b, ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

n, k = map(int, input().split())
ans = 0
for i in range(1, n + 1):
    #divmod: 割り算の商と余りを同時に取得
    p, r = divmod(n, i)
    ans += p * max(0, i - k) + max(0, r - k + 1)
print(ans if k != 0 else ans - n)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    #divmod: 割り算の商と余りを同時に取得
    p,r = divmod(n, i)
    # print(f"i {i}, p {p}, r {r}")
    # print("1", p*max(0,i-k))
    # print("2", max(0,r-k+1))
    ans += p*max(0,i-k)+max(0,r-k+1)
print(ans if k != 0 else ans - n)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
"""
bを固定して、aの数を数える
(b-k) * (N//b) + min(0,n%b - k +1)
注意するのは、k >= b なら0 
"""
ans = 0
# b を動かす
for b in range(k + 1, n + 1):
    ans += (b - k) * (n // b) + max(0, n % b - k + 1)
    # print(ans, b)
if k == 0:
    print(n ** 2)
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, K = in_nn()

    ans = 0
    for b in range(K + 1, N + 1):
        q, r = divmod(N, b)
        ans += q * (b - K) + max(0, r - K + 1)
        if K == 0:
            ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


    ans = 0

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


main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def prime_factorize(N):
    prime_list = []
    while N % 2 == 0:
        prime_list.append(2)
        N //= 2
    f = 3
    while f**2 <= N:
        if N % f == 0:
            prime_list.append(f)
            N //= f
        else:
            f += 2
    if N != 1:
        prime_list.append(N)
    return prime_list

def main():
    N, K = map(int, input().split())
    if K == 0:
        print(N*N)
        exit()
    ans = 0
    for i in range(1,N+1):
        if i <= K:
            ans += N
        else:
            ans += K * (N//i) + min(K,N%i+1) - 1
        # print(ans)
    print(N*N - ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    if k == 0:
        print(n ** 2)
        exit()

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
ans = 0
for b in range(k + 1, n + 1):
    m = n // b
    ans += m * (b - k)  # [k,b)
    ans += max(0, (n % b) - max(0, k - 1))
print(ans)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, k = LI()
if k == 0:
    print(n ** 2)
    quit()
ans = 0
for b in range(1, n+1):
    x, y = divmod(n, b)
    z = b - k
    if z < 0:
        continue
    if y - k + 1 < 0:
        ans += z * x
    else:
        ans += z * x + (y - k + 1)
print(ans)

Submission status: Accepted

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

ans = 0
if k == 0:
    ans = n ** 2
else:
    for b in range(1, n+1):
        if b > k:
            loop_num = n // b #繰り返し回数
            loop_last = n - loop_num * b #ラストの途中で途切れてる部分
            ans += (b-k) * loop_num + max(0, loop_last - k + 1)

print(ans)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

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

Submission status: Accepted

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

ans = 0
for mod in range(1, N + 1):
    q, r = divmod(N, mod)
    ans += max(0, mod - K) * q + 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 ** 2)
    exit()

ans = 0
for mod in range(1, N + 1):
    q, r = divmod(N, mod)
    ans += max(0, mod - K) * q + max(0, r - K + 1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())

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

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


if __name__ == '__main__':
    resolve()

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:
        ans-=1
print(ans)

Submission status: Accepted

Solution code:
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)+max(0,N%i-(K-1))
print(ans)

Submission status: Accepted

Solution code:
import sys


def solve(x):
    return (x - k) * (n // x) + max(0, n % x - k + 1)


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

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


ans = 0
for i in range(k + 1, n + 1):
    ans += solve(i)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

if k==0:
    print(n*n)
    sys.exit()

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

print(s)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
# bを全探索して組み合わせの数を求める
for b in range(1, N+1):
    # 繰り返される数
    times = (N//b)
    # 最後に付け加える数
    last = N % b
    ans += times * max(0, b-K) + max(0, last - K + 1)
if K == 0:
    print(N*N)
else:
    print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if k==0:
    print(n**2);exit()
def f(b):
    return (b-k)*(n//b)+max(0,1+n-(n//b)*b-k)
print(sum(f(i)for i in range(k+1,n+1)))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
if k==0:
    print(n**2);exit()
def f(b):
    return (b-k)*(n//b)+(max(0,1+n-(n//b)*b-k) if n%b else 0)
print(sum(f(i)for i in range(k+1,n+1)))

Submission status: Accepted

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

ans = 0
for b in reversed(range(1, n+1)):
    if b == k:
        break
    y_cnt = b-k
    p, q = divmod(n, b)
    ans += y_cnt*p
    if k <= q:
        ans += q-max(k-1, 0)
print(ans)

Submission status: Accepted

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

ans = 0
for b in reversed(range(1, n+1)):
    if b == k:
        break
    y_cnt = b-k
    p, q = divmod(n, b)
    ans += y_cnt*p
    if q == 0:
        continue
    if k <= q:
        ans += q-max(k-1, 0)
print(ans)

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-max(0, k-1))
print(ans)

Submission status: Accepted

Solution code:

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()
    output = 0
    for b in range(1, N+1):
        output += N//b * max(0, b-K)
        output += max(0, N%b-K+1)
        if K == 0: output -= 1
    print(output)

    return

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):
        ans += ((n-b+1)//b + 1)*(b-k)
        if k - 1 < n % b < b-1:
            ans += n % b - k + 1
print(ans)

Submission status: Accepted

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

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

for i in range(k+1, n+1):
    cnt = (i-1)-k+1
    add = n // i * cnt
    if n % i >= k:
        add += (n % i) - k + 1
    res += add

print(res)

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()

    lim = 10 ** 5

    ans = 0
    for i in range(max(1, k + 1), n + 1):
        tmp1 = (i - k) * (n // i)
        tmp2 = max(n % i - max(k - 1, 0), 0) if n % i else 0
        ans += tmp1 + tmp2
        # print(i, tmp1, tmp2, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if k==0:
    print(pow(n,2))
    exit()

ans=0
# あまりの数で場合わけ
for i in range(k,n+1):
    ans+=n-i
    for j in range(1,int(pow(n-i,0.5))+1):
        ans+=max((n-i)//j-i,0)
        if j>i:
            ans+=max((n-i)//j-int(pow(n-i,0.5)),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):
        period = n // b
        nokori = n % b
        ans += period * (b - k) + max(nokori - k + 1, 0)
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
b = K+1
while b <= N:
  p = N//b
  r = N%b
  ans += p*max(0,b-K)+max(0, r-K+1)-(0 if K > 0 else 1)
  b += 1
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
result = 0
for b in range(k+1,n+1):
  roop = n //b
  roop_ok = (b-1) - (k-1)
  amari = n % b
  amari_ok = amari - k + 1
  if roop_ok >= 0 :
    result += roop * roop_ok
    if amari_ok > 0 :
      result += amari_ok
      
if k == 0:
  print(n**2)
else:
  print(result)

Submission status: Accepted

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

ret = 0

for b in range(k+1, n+1):
    div = n // b
    ama = n % b
    if k != 0:
        ret += div * (b - k) + max(ama - k + 1, 0)
    else:
        ret += div * (b - k) + max(ama, 0)

print(ret)

Submission status: Accepted

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

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

print(num)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()

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

print(ans)