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

input = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    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 * (b-K) + max(N%b - (K-1), 0)
    print(ans)


if __name__ == '__main__':
    main()

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)
if K == 0:
    ans -= N
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

for b in range(K+1, N+1, 1):
    cnt += 1
    tmp = (N - (K + cnt - 1)) // b
    ans += cnt * (tmp + 1)
    if (tmp + 1) * b + K <= N:
        ans += N - ((tmp + 1) * b + K) + 1
    ##print(b, ans)

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(2,n+1):
    ans += (n//i) * max(0,i-k) + max(0,(n%i)-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 = N//b
    R = N%b
    ans += Q*(b-K)+max(0,R+1-K)
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()
  
ans = 0
for b in range(1, N+1):
  ans += int(N/b) * max(0, b-K)
  ans += max(0, N%b + (1-K))

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):
    val1 = N // b * (b - K)
    if N % b == 0:
        val2 = 0
    else:
        val2 = max(0, N - (N // b) * b - K + 1)
    ans += val1 + val2
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# ABC090 D - Remainder Reminder
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,k=nm()
ans=0

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if k == 0:
    s = n*n
print(s)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
if K == 0:
  ans = N * N
else:
  for b in range(K+1,N+1):
    k, m = N//b, N%b
    ans += k*(b-K)
    if m != 0:
      ans += max(m-K+1, 0)
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(0, b-K)*(N//b) + max(0, N%b-K+1)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if K == 0:
    print(N * N)
else:
    ans = 0
    for b in range(K + 1, N + 1):
        ans += (N // b) * (b - K)
        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()
ans = 0
for i in range(N - K):
    b = K + 1 + i
    n1 = N // b
    if n1 > 0:
        n2 = max(0, N % b - K + 1)
        ans += (i + 1) * n1 + n2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    ans = 0
    if K == 0:
        return print(N**2)
    for a in range(1, N+1):
        r = N % a
        p = (N - r) // a
        ans += p * max(0, a - K)
        ans += max(0, r - K + 1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K = MI()
    if K==0:
        print(N**2)
        return
    ans = 0
    for b in range(K+1,N+1):
        roop = N//b
        ans += roop*(b-K)
        remain = N-roop*b
        ans += max(0,remain-K+1)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

"""data = input()
data = data.split(" ")
n = int(data[0])
k = int(data[1])
sum = 0
for b in range(1, n+1):
    sum += (n//b*max(0,b-k)+max(0,n%b-k+1))
if k == 0: sum-=n
print(sum)"""

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
for b in range(K+1,N+1):
    x = (b-K)*(N//b) + max(0,(N%b)-K+1)
    # print(b,"num",x)
    cnt+= x

if K == 0:
    print(N**2)
else:
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

print(res)

Submission status: Accepted

Solution code:
import sys

n, k = map(int, sys.stdin.readline().split())

def main():
    res = 0
    for b in range(k+1, n+1):
        q, r = divmod(n, b)
        res += q * (b - k) + max(0, r - (k - 1))
    if k == 0:
        res -= n - k
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys

n, k = map(int, sys.stdin.readline().split())

def main():
    res = 0
    for b in range(k+1, n+1):
        q, r = divmod(n, b)
        res += q * (b - k) + max(0, r - (max(k, 1) - 1))
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()

cnt = 0
for a in range(1, N+1):
    # mod a毎にまとめて追加
    d, m = divmod(N, a)
    cnt += max(0, a-K) * d
    cnt += max(0, m - max(0, K-1))
print(cnt)

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):##境界の処理とか+1の有無とかが難しい
    quo = n//b
    by_rem = b-k
    ans += quo * by_rem
    
    ans += max(0, n%b-k+1)
    
    
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for b in range(k+1, n+1):
    candidate = (n // b) * (b - k)
    mod = n % b
    if mod >= k:
        add = mod - k + 1
        if k == 0:
            add -= 1
        candidate += add
    count += candidate

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def check():
    N,K = map(int, input().split())
    total = 0
    
    if K == 0: return N**2
    
    for b in range(1,N+1):
        if b <= K:
            continue
        
        amari = N-b*(N//b)        
        test = amari-K+1 if amari >= K else 0           
        total += (b - K) * (N//b) + test
    return total
print(check())

Submission status: Accepted

Solution code:
def counter(b,N,K):
    return(max((N//b)*(b-K)+max(N%b-K+1,0),0))

N,K=map(int,input().split())
ans=0
for i in range(1,N+1):
    ans+=counter(i,N,K)

if K==0:
    print(N**2)
else:
    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):
        c = 0
        a = k+c*b
        while a <= n:
            if a != 0:
                if a+b-k <= n:
                    ans += b-k
                else:
                    ans += n-a+1
            else:
                if a+b-k <= n:
                    ans += b-k-1
                else:
                    ans += n-a
            c += 1
            a = k+c*b
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]

ans = 0
for m in range(1, N+1):
    if m <= K:
        continue
    maxlen, mod = divmod(N, m)
    ans += maxlen * (m - K)
    
    ans += max(0, N - m * maxlen - K + 1)
    if K == 0:
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split());print(sum(n//i*(i-k)+n%i-min(max(k-1,0),n%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)
else:
    #bの値かな
    co=0
    for i in range(k+1,n+1):
        co+=(n//i)*(i-k)
        co+=max(n%i-k+1,0)
    print(co)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    cnt = 0
    for i in range(1, n + 1):
        if i > k:
            cnt += int((n - n % i) / i * (i - k) + max(0, n % i - max(1, k) + 1))
    print(cnt)


if __name__ == '__main__':
    solve()

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

Submission status: Accepted

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

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):
    ans += max(0, b-K)*(N//b)
    ans += max(0, N % 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):
    before_range = max((N % i - K + 1) , 0)
    before_cnt = (N // i + 1)
    before = before_cnt * before_range
    after_range = min((i - 1) - (N % i) , (i - 1) - K + 1)
    after_cnt = (N // i)
    after = after_cnt * after_range
    now = before + after
    if K == 0:
        now -= 1
    #print(now)
    ans += now
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, K: int):
    if K!=0:
        ans = 0
        for j in range(K+1,N+1):      
            ans += (j-K) * (N//j)
            if N%j >=K:
                ans += N%j - K + 1
    else:
        ans = N * N

    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve(N: int, K: int):
    if K!=0:
        ans = 0
        for j in range(1,N+1): #10**5ループなのでいけるはず。
            if K <= j-1:
                ans += (j-K) * (N//j)
                if N%j >=K:
                    ans += N%j - K + 1
    else:
        ans = N * N

    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

#愚直解 10**5 * 10**5 = 10**10でTLEになる
#ans = 0
#for i in range(1,N+1):
#    for j in range(1,N+1):
#        if i%j>=K:
#            ans += 1
 
#i%jの表
#	j
#i	1	2	3	4	5	6	7	8	9	10	11	12	13	14	15
#1	0	1	1	1	1	1	1	1	1	1	1	1	1	1	1
#2	0	0	2	2	2	2	2	2	2	2	2	2	2	2	2
#3	0	1	0	3	3	3	3	3	3	3	3	3	3	3	3
#4	0	0	1	0	4	4	4	4	4	4	4	4	4	4	4
#5	0	1	2	1	0	5	5	5	5	5	5	5	5	5	5
#6	0	0	0	2	1	0	6	6	6	6	6	6	6	6	6
#7	0	1	1	3	2	1	0	7	7	7	7	7	7	7	7
#8	0	0	2	0	3	2	1	0	8	8	8	8	8	8	8
#9	0	1	0	1	4	3	2	1	0	9	9	9	9	9	9
#10	0	0	1	2	0	4	3	2	1	0	10	10	10	10	10
#11	0	1	2	3	1	5	4	3	2	1	0	11	11	11	11
#12	0	0	0	0	2	0	5	4	3	2	1	0	12	12	12
#13	0	1	1	1	3	1	6	5	4	3	2	1	0	13	13
#14	0	0	2	2	4	2	0	6	5	4	3	2	1	0	14
#15	0	1	0	3	0	3	1	7	6	5	4	3	2	1	0

#縦方向で周期的になっている ∴jでループさせる。
#j*(N//j) : 1 ～ j-1 , 0 までを N//j回 繰り返し。
#そこから : 1～N%j までが 1回ずつ

if K!=0:
    ans = 0
    for j in range(1,N+1): #10**5ループなのでいけるはず。
        if K <= j-1:
            ans += (j-K) * (N//j)
            if N%j >=K:
                ans += N%j - K + 1
else:
    ans = N * N

print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(k+1,n+1):
    a = n // i
    ans += (i-k) * a
    if k <= n % i and n % i != 0:
        ans += n % i - k + 1
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
 
count = 0
 
# N = n*b + r
for b in range(1,N+1):
    n = N // b
    r = N % b
    count += n*max(0,b-K) + max(0,r-K+1)
 
# a=0の場合を引く
if K==0:
    count -= N
 
print(count)

Submission status: Accepted

Solution code:
def examD():
    N, K =LI()
    cur = 0
    for i in range(K+1,N+1):
        cur +=((N//i)*(i-K) + max(0,N%i-K+1))
#        print(cur,i)
    if K==0:
        cur -=N
    print(cur)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

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 >= N // i * i + K:
        ans += N - (N // i * i + 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 += N//b * (b-K) + max(N%b - K + 1, 0)
print(ans if K else N*N)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    if(k==0):
        print(n**2)
        return
    ans=0
    for b in range(k+1,n+1):
        q=(n-k)//b+1
        ans+=q*(b-k)-max(0,(q*b-1)-n)
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

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

main()

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)
  x=n%i
  ans+=max(0,x-k+1)
if k==0:
  print(n*n)
else:
  print(ans)

Submission status: Accepted

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

for b in range(K+1,N+1):

  count += (b-K)*(N//b) + max(0, (N%b) - K +1)
  
if K == 0:
  count = N*N

  
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
if k==0:
    print(n*n)
    exit()
for i in range(1,n+1):
    if i-1>=k:
        ans+=n//i*(i-k)+max(n%i-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):
    k = N // b
    res = N - k*b
    ans += k * (b-K)
    if res >= K:
        ans += res - K + (K!=0)

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n,k=map(int,input().split())
tmp=0
ans=0
# if k==0:
#     print(n*n)
#     quit()
for i in range(k,n):
    tmp=n//(i+1)
    ans+=(i+1-k)*tmp
    tmp=max(1,k)
    if n%(i+1)-tmp+1>0:
        ans+=n%(i+1)-tmp+1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n,k=map(int,input().split())
tmp=0
ans=0
if k==0:
    print(n*n)
    quit()
for i in range(k,n):
    tmp=n//(i+1)
    ans+=(i+1-k)*tmp
    if n%(i+1)-k+1>0:
        ans+=n%(i+1)-k+1
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(1,N+1):
  if b <= K: continue
  else: ans += N//b*(b-K) + max(0,(N-(N//b)*b)-K+1)

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

Submission status: Accepted

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

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

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

print(answer)

Submission status: Accepted

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

if K == 0:
    print(N * N)
else:
    cnt = 0
    for b in range(1, N+1):
        l_max = N // b
        for l in range(l_max + 1):
            k = min(b-1, N - b*l)
            if k >= K:
                cnt += k - K + 1

    print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
res = 0
if k == 0:
    res = n**2
else:
    for i in range(k+1,n+1):
        res += (i - k)*((n+1) // i)
        t = n % i
        if t == i-1:
            continue
        if t >= k:
            res += t-k+1
print(res)

Submission status: Accepted

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

for i in range(1,n+1):
    if i <= k:
        continue
    count += max(0, (n%i) - k + 1)
    count += (n // i) * (i - k)
print(count)

Submission status: Accepted

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


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

if k==0:
    print(ans-n)
else:
    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(b-k,0)
	ans+=max(0,n%b-k+1)
if k==0:
	print(n**2)
	exit()
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

def NK():
    return map(int,input().split())

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
count = 0
#when k <= i < j,  i % j >= k
if k == 0:
    print(n ** 2)
    exit()
for i in range(1, n + 1):
    if i <= k:
        continue
    count += max(0, (n % i) - k + 1)
    count += (n // i) * (i - k)
print(count)

Submission status: Accepted

Solution code:
# a%b >= K iff xb+K <= a < (x+1)b
# bごとに数えるだけ

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

for b in range(K+1,N+1):
  cnt = 0
  x_max = N//b
  # 0 <= x < x_max
  # 各xに対してb-K個ある
  cnt += x_max * (b-K)
  # x = x_max
  lower = x_max*b+K
  if lower <= N:
    upper = min((x_max+1)*b-1,N)
    cnt += upper - lower + 1
  ans += cnt

# N=0除外
if K == 0:
  ans -= N
  
print(ans)

Submission status: Accepted

Solution code:
# editrialを参考にした
N, K = map(int, input().split())
ans = 0
for b in range(1, N + 1):
    div, mod = divmod(N, b)
    ans += div * max(0, b - K)
    ans += max(mod - K + 1, 0)
if K == 0:
    ans -= N
print(ans)

Submission status: Accepted

Solution code:
def solve(n, k):
    cnt = 0
    if k == 0:
        return n * n
    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
    return cnt

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(c)

Submission status: Accepted

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

# 全てのbの候補について、aの候補の個数をかけ合わせる

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

Submission status: Accepted

Solution code:
import sys


n, k = [int(_) for _ in input().split()]
if k == 0:
    print(n*n)
    sys.exit()
ans = 0
m = n-k
t1 = 0
t2 = 0
t3 = 0
ans += ((m*m - m) // 2) + m
for i in range(k+1, n+1):
    t1 = n-i+1
    t2 = t1 // i
    t3 = t1 % i
    ans += t2 * (i-k)
    if t3 > k:
        ans += t3 - k
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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

ans = 0
for i in range(1, N+1):
	p = N//i
	r = N%i

	ans += p * max(0, i-K) + max(0, r-K+1)

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

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
ans =0
for i in range(K+1,N+1):
  #print((N//i)*(i-K),N%i+1-K)
  ans += (N//i)*(i-K)
  if N%i!=0 and K!=0:
    ans +=max((N%i+1-K),0)
  elif N%i!=0 and K==0:
    ans +=(N%i)
print(ans)

Submission status: Accepted

Solution code:
import math 
n,k=map(int,input().split())
if k==0:
    print(n**2)
if k>=1:
    ans=0
    flow=0
    for some in range(k+1,n+1):
        flow=math.floor(n/some)*(some-k)
        ans+=flow
        if  math.floor(n/some)*some+k>n:
            ans=ans
        if math.floor(n/some)*some+k<=n:
            ans=ans+n+1-math.floor(n/some)*some-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(K+1,N+1):
    # N = b * num + rest
    num = N // b 
    rest = N - (b*num)
    # b一周期の中に、余りがK以上になる数字が(b-K)個、残りの中でさらに余りがKを超える物があればそれも加算
    ans += (b - K) * num + max(0, rest-K+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):
    if N % i < K:
        temp = 0
    else:
        temp = N % i - K + 1

    ans += N // i * (i - K) + temp

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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