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
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        for _ in range(num): return []
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list,zip(*read_all))

#################

N,K = II()
ans = 0
for b in range(K+1,N+1):
    i = math.floor((N-K)/b)
    ans += i*(b-K) + min(N-(K+i*b)+1, b-K)

if K==0:
    ans -= N-K

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
from functools import reduce
import math

input = sys.stdin.readline


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

if k == 0:
    cnt -= n

print(cnt)

Submission status: Accepted

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

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

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

cnt = 0
for b in range(k + 1, n + 1):
    q, r = divmod(n - k + 1, b)
    cnt += (b - k) * q + min((b - k), r)

print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


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



if k:
    print(ans)
else:
    print(n ** 2)

Submission status: Accepted

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

if k == 0:
    ans = n ** 2
else:
    ans = 0
    for i in range(k+1,n+1):
        j = n - k + 1
        a, b = j // i, j % i
        ans += a * (i-k) + min(b, i-k)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def solve(N, K):
    # N <= 10^5
    if K == 0:
        return N * N
    cnt = 0
    for b in range(K, N+1):
        q, r = divmod(N, b)
        cnt += max(0, b-K) * q + max(0, r - K + 1)
    return cnt

assert solve(5, 2) == 7
assert solve(10, 0) == 100
N, K = map(int, input().split())
print(solve(N, K))

Submission status: Accepted

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

Submission status: Accepted

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

    if K == 0:
        return N * N

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def updiv(a,b):

    if a % b == 0:

        return a // b

    else:

        return a // b + 1


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

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

else:

    for i in range(N):

        i += 1

        if i < K:
            continue;

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

        nk = N - (N // i) * i

        ans += max(0 , nk - (K-1))

    print (ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = SR(3)
    for i in range(3):
        print(s[i][i], end="")
    print()
    return

#B
def B():
    a, b = LI()
    ans = 0
    for i in range(a, b + 1):
        x = str(i)
        for k in range(len(x)//2):
            if x[k] != x[-k - 1]:
                break
        else:
            ans += 1
    print(ans)
    return

#C
def C():
    n, m = LI()
    if n == m == 1:
        print(1)
        return
    if n == 1 or m == 1:
        print(max(n - 2, m - 2))
        return
    if n == 2 or m == 2:
        print(0)
        return
    print(n * m - n * 2 - (m - 2) * 2)
    return

#D
def D():
    n, k = LI()
    ans = 0
    if k == 0:
        print(n * n)
        return
    for b in range(k + 1, n + 1):
        tmp1, tmp2 = n // b, n % b
        ans += tmp1 * (b - k) + max(tmp2 - k + 1, 0)
    print(ans)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC090D - Remainder Reminder (ARC091D)
def main():
    N, K = tuple(map(int, input().split()))
    if K == 0:
        print(N ** 2)
        return
    ans = 0
    for i in range(K + 1, N + 1):
        ans += N // i * (i - K) + max(0, (N % i) - K + 1)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

result = 0
for i in range(K+1, N+1):
  loop = int(N/i)
  result += (i-K)*loop
  result += max(N-K-(loop*i)+1,0)

print(result)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, k = (int(i) for i in input().split())
cnt = 0
for x in range(k+1, n+1):
    cnt = cnt + int(n / x) * (x - k) + max(int(n % x) - (k - 1), 0)
    #print(int(n / x) * (x - k), end=" ")
    #print(max(int(n % x) - (k - 1), 0))
if k == 0:
    cnt = cnt - n
print(cnt)

Submission status: Accepted

Solution code:
import math

def count(n, k, b):
    if k >= b:
        return 0
    n_blocks = math.floor((n+1) / b)
    ans = (b-k) * n_blocks

    remainder = (n+1) - n_blocks * b
    if remainder > k:
        ans += remainder - k

    #print(f'b={b}, ans={ans}, n_blocks={n_blocks}, remainder={remainder}')
    return ans

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

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

ans = 0
for b in range(1, n+1):
    cnt = count(n, k, b)
    ans += cnt
    #print(f'b={b}, cnt={cnt}, n={n}, k={k}')
print(ans)

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, K: int):
    counter = 0
    for b in range(1, N+1):
        p = N // b
        r = N % b
        counter += p * max(0, b-K)
        counter += max(0, r-K+1)
    if K > 0:
        print(counter)
    else:
        print(counter - N)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
n,k=map(int,input().split())
if k==0:
    print(n*n)
else:
    a=0
    for b in range(n+1):
        if k<b:a+=n//b*(b-k)+max(0,n-n//b*b-k+1)
    print(a)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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):
    max_p = N // b
    max_q = N % b
    if max_q < K:
        max_p -= 1
        max_q = b - 1
    # print(b,max_p,max_q)
    ans += max_p * (b-K) + (max_q-K+1)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

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

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########
    
def main():
    N, K = l_inpl()

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

    ans = 0
    for b in range(1, N+1):
        if b < K:
            continue
        p = N//b
        r = N%b
        ans += max(b-K, 0) * p + max(r-K+1, 0)
    print(ans)
if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, k = rli()
    if k == 0:
        print(n*n)
        return
    ans = 0
    for b in range(1, n+1):
        if b <= k:
            continue
        ans += (n // b)*(b-k)
        ans += max(0, n%b-k+1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7


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

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**2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
def kosuu(n,b,k):
    res = 0
    res += n//b * (b-k)
    diff = n%b - k
    if diff >= 0:
        res += diff + 1
    return res

cnt = 0
for b in range(K+1,N+1):
    ko = kosuu(N,b,K)
    # print(b,ko)
    cnt += ko

if K == 0:
    cnt -= N

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__=="__main__":
  main()

Submission status: Accepted

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

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

if K == 0:
    ans = N**2

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

Submission status: Accepted

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

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

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 > 0:
    ans += (n // b) * (b-k)
    
  # 繰り返し範囲外
  if ((n - (n // b)*b) - (k-1)) > 0:
    ans += ((n - (n // b)*b) - (k-1))


  
  
print(ans)

Submission status: Accepted

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

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): ## b in [K+1,N]
  var1 = b-1 - K + 1
  Nmodb = N // b
  if N < K + Nmodb * b:
    var2 = 0
  else:
    var2 = N - (K+Nmodb*b) + 1
  ans += var1 * Nmodb + var2
  #print(b, var1, Nmodb, var2, var1 * Nmodb + var2)
  
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):
        p = n // b
        r = n % b
        ans += p * max(0, b - k) + max(0, r - k + 1)
    ans += n - k
print(ans)

Submission status: Accepted

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

ans = 0
for b in range(1, N+1): #bを全探索
    amari = max(b-K, 0)
    count = N // b
    # print ('b=', b)
    # print (count * amari + max(N%b - K + 1, 0))
    ans += count * amari + max(N%b - K + 1, 0)

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





#以下単純な全探索O(N^2)となり間に合わない
# count = 0
# for a in range(1,N+1):
#     for b in range(1,N+1):
#         if a%b >= K:
#             count += 1

# print (count)

Submission status: Accepted

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

Submission status: Accepted

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

if k != 0:
    counter = 0
    for b in range(k+1, n+1):
        counter += (n // b) * (b - k) + (n % b) - min(n % b, k - 1)
    print(counter)
else:
    print(n ** 2)

Submission status: Accepted

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


def solve(N: int, K: int):
    ret = 0
    if K == 0:
        ret = N * N
    else:
        for k in range(K + 1, N + 1):
            tmp = N // k
            mod = N % k
            ret += tmp * (k - K)
            ret += max(0, mod - K + 1)
            #print(k, tmp, k - K, mod, ret)
    print(ret)
    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:
N, K = map(int, input().split())

ans = 0
N += 1
# a = b * x + K'(K >= K)
for b in range(K+1, N):
    max_x = N // b
    ans += max_x * (b - K) + max(N-b*max_x-K, 0)
    if K == 0:
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


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

    ans = 0

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

    ans = 0
    for amari in range(k, n):
        max_shou = (n - amari) // (amari + 1)
        if amari > 0:
            ans += n - amari
        for shou in range(1, max_shou + 1):
            start = (amari + 1) * shou + amari
            nokori = n - start + 1
            ans += math.ceil(nokori / shou)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#ABC090-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,k=IL()
ans=0
for i in range(1,n+1):
    ans+=max(i-k,0)*(n//i)
    ans+=max(0,n%i-k+1)
if k==0:
    ans=n*n
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
from sys import *
N,K=map(int,raw_input().split())

b=K+1
ans=0
if K==0:
    print(N*N)
    exit(0)

while b<=N:
    s=0
    bNum=(N+1)/b
    s+=bNum*(b-K)
    if (N+1)%b!=0:
        s+=max(0,((N)%b)-K+1)
    ans+=s
    b+=1

print(ans)

Submission status: Accepted

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

if (K!=0):
  s=0
  for b in range(K+1,N+1):
    w = N//b
    a = N%b
    ds = 0
    ds+= max(a-K+1,0)# amari <= a
    ds+= w*(b-K)

    s+=ds
    #print(b,ds)
  print (s)
else:
  print (N*N)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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

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

    res = 0
    for b in range(1, n + 1):
        p, r = divmod(n, b)
        ok = max(0, b - k)
        res += ok * p + max(0, r - k + 1)

    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
	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)
	if K == 0:
		ans -= N

	print(ans)


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 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
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+=(N//i)*(i-K)
    if N%i>K-1: ans+=N%i-K+1

print(ans)

Submission status: Accepted

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

        x = N // b
        y = N % b

        ans += x * (b-K)
        if y >= K:
            ans += y-(K-1)


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