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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *

N, K = MAP()

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%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(k, n+1):
    p = n // i
    r = n % i
    ans += p * (i - k) + max(0, (r - 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):
    one_loop_k = b-k
    if one_loop_k <=  0: continue
    loop_cnt = n//b
    ans += one_loop_k*loop_cnt

    rem = n-loop_cnt*b
    ans += max(0,rem-k+1)
    # print(b,ans)

print(ans)

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def main():
    N, K = mi()
    ans = 0
    for b in range(K+1, N+1):
        q = 0
        while K+b*q <= N:
            ans += min((q+1)*b, N+1)-(K+b*q)
            q += 1
    if K == 0:
        ans -= N
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

for b in range(k+1,n+1):
	p,r=divmod(n,b)
	cnt+=p*(b-k)+max(0,r-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 r in range(K, N):
  for q in range((N-r)//(r+1) + 1):
    if q == 0:
      ans += N - r
    else:
      ans += max(0, (N-r)//q - r)

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
s = 0
for i in range(1, n+1):
    q, r = divmod(n+1, i)
    s += q*max(i-k, 0) + max(r-k, 0)
s -= n * (k==0)
print(s)

Submission status: Accepted

Solution code:
#bはKより真に大きい、N以下
#aはK以上

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

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

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""
全体からあまりがK未満を引く
"""
N, K = lr()
total = N * N
for b in range(1, N+1):
    if b <= K:
        total -= N
    else:
        total -= K * (N // b) + max(0, min(N % b, K - 1))
    #print(b, total)

answer = total
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

cnt = 0
for b in range(max(1, K), N+1):
    cnt += N-max(1, K)+1
    if b!=0:
        cnt -= K*(N//b)
        if b*(N//b)+(K-1) > N:
            cnt += b*(N//b)+(K-1) - N

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

if k==0:
    ans = (1+n-1)*(n-1)//2
else:
    ans = (1+n-k)*(n-k)//2


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

for i in range(k,n):
    if i==0:
        continue
    for j in range(1,n//i+1):
        if j*(i+1)+i<=n:
            ans+=(n-(j*(i+1)+i))//j+1
        if j*(i+1)+i>n:
            break

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(N,K):
    if K == 0:
        return N**2
    else:
        ans = 0
        for b in range(K+1,N+1):
            #b <= a <= Nで a mod b >= Kを満たすaの個数
            q,r = N//b,N%b
            ans += (q*(b-K) + max(0,r-K+1))
        return ans

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

    print(solve(N,K))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = map(int, readline().split())
    ans = 0

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int, open(0).read().split())
ans = 0
if K == 0:
    print(pow(N,2))
else:
    for b in range(K+1,N+1):
        d, m = divmod(N,b)
        ans += d * (b-K) + max(0,(m-K+1))
    print(ans)

Submission status: Accepted

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

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, k = list(map(int, input().split()))
    ans = 0
    for b in range(1, n + 1):
        q, r = divmod(n, b)
        ans += q * max(0, b - k)
        ans += max(0, r - 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:
    print(n**2)
    exit()
for i in range(k+1,n+1):
    ans += (i-k) * (n//i)
    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()
ans = 0
for b in range(k+1,n+1):
    p = n//b
    r = n%b
    ans += max(b-k,0)*p + max(r+1-k,0)
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):
        p = n // b
        ans += (b-k)*p
        r = n % b
        if r >= k:
            ans += r-k+1
print(ans)

Submission status: Accepted

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

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

ans = 0
for b in range(k + 1, n + 1):
    q, mod = divmod(n, b)
    ans += q * (b - k)
    if mod >= k:
        ans += mod - k + 1
print(ans)

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 += max(0, i-K) * p + max(0, r-K+1)
    if K == 0:
        ans -= 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    if k == 0:
        print(n * n)
        return
    ans = 0
    for i in range(k + 1, n + 1):
        p, q = divmod(n, i)
        ans += p * (i - k) + max(q - 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**2)
else:
    ans = 0
    for b in range(k,n+1):
        ans += (n//b)*(b-k)
        if n%b>=k:
            ans += n%b-(k-1)
    print(ans)

Submission status: Accepted

Solution code:
import sys
N, K = map(int, sys.stdin.readline().rstrip().split())
if K == 0:
    print(N ** 2)
    exit()
ans = 0
for b in range(1, N + 1):
    if b - 1 < K:
        continue
    ans += (N // b) * (b - K) + (max(N % b - K + 1, 0))
print(ans)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,K = IL()

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

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

Submission status: Accepted

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

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

print(ans)

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+1)//b*(b-K)+max(0, (N+1)%b-K))
    #print(b, ans)
  if K == 0:
    ans -= (N-K)
  print(ans)
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
N, K = 5, 2

# N, K = 31415, 9265
#
# N, K = 10, 0

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


def calculate(n, k):
    result = 0
    for b in range(1, N + 1):
        p = n // b
        s1 = p * max(0, (b - 1 - (k - 1)))
        s2 = max(0, (n % b) - (k - 1))

        res = s1 + s2
        if k == 0:
            result = result + res - 1
        else:
            result = result + res

    print(result)


calculate(N, K)

Submission status: Accepted

Solution code:
def count_possible_pairs(N, K):
  if K == 0:
    return N**2
  else:
    cnt = 0      
    for b in range(K+1, N+1):
      block = (N+1) // b
      cnt += block * (b - K)    # remainders are K, K+1, ..., b-1
      res = (N+1) % b
      if res > K:
        cnt += (res - K)
    return cnt




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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, K = list(map(int, input().split(' ')))
    # K < b <= N
    # a =  K, ..., b - 1  # if K = 0, exclude the a = K case
    #      b + K, ..., b + b - 1
    #      2 * b + K, ..., 2 * b + b - 1
    #      ...
    ans = 0
    for b in range(K + 1, N + 1):
        ans += (N // b) * (b - K)
        ans += max([0, N % b - K + 1])
        if K == 0:
            ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

Submission status: Accepted

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

cnt=0

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

if K>0:
    print(cnt)
else:
    print(N*N)

Submission status: Accepted

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

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

Submission status: Accepted

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

#a=b*x+kk  (k<kk<b)

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

cnt=0
for b in range(k+1,n+1):
    ux=n//b
    if n%b==0:
        umod=0
    else:
        umod=max(0,n%b-k+1)
    dmod=max(0,b-k)
    #print(b,"##############")
    #print(umod,dmod)

    cnt+=umod+dmod*(ux)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))


N, K = mi()

cnt = 0
for b in range(K+1, N+1):
    #print(cnt)
    for x in range((N-K)//b+1):
        #print('a', min(N-(b*x+K), b-K))
        if b*x+K == 0:
            cnt -= 1
        cnt += min(N-(b*x+K)+1, b-K)
print(cnt)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N, K = getNM()
sum = 0
for b in range(1, N + 1):
    opt1 = (N // b) * max(0, (b - K))
    if K == 0:
        opt2 = N % b
    else:
        opt2 = max(0, (N % b) - K + 1)
    sum += (opt1 + opt2)
print(sum)

Submission status: Accepted

Solution code:
import sys


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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    res = 0
    for b in range(1, N+1):
        p = (N+1) // b
        r = (N+1) % b
        res += max(b - K, 0) * p + max(r - K, 0)
    
    if K == 0:
        print(N ** 2)
    else:
        print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, K = map(int, input().split())
a = [i for i in range(1, N + 1)]
ans = 0
for b in range(1, N + 1):
    if K >= b:
        continue
    else:
        if K != 0:
            ans += (N // b) * (b - K) + max((N % b) - K + 1, 0)
        else:
            ans += N
print(ans)

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
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+=N//b*(b-K)+max(N%b-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 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())
ans = 0
for p in range(K+1, N+1):
  k = N//p
  l = N%p
  a = k*(p-K)+ max(l-K+1,0)
  if(K == 0):
    a -= 1
  ans += a
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 += N//b*(b-K) + max(0,N%b-K+1)
    print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    if K == 0:
        print(N ** 2)
        return
    ans = 0
    for b in range(K, N+1):
        r = (N+1) % b
        p = (N+1) // b
        ans += (b-K) * p + max(0, r - K)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())

    if k==0:
        print(n**2)
    else:
        res=0
        for b in range(1,n+1):
            if b<=k:
                continue
            else:
                m=n//b
                l=n%b
                res+=(b-k)*m
                res+=max(0,l-k+1)

        print(res)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, k = map(int, input().split())
if k == 0:
    print(n ** 2)
else:
    ans = 0
    for b in range(k + 1, n + 1):
        ans += n // b * (b - k)
        ans += max(n % b - (k - 1), 0)
    print(ans)

Submission status: Accepted

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


def f(n, N, K):
    '''
    >>> f(2, 10, 2)
    0
    >>> f(1, 10, 0)
    10
    >>> f(1, 10, 1)
    0
    >>> f(2, 10, 1) # 1, 3, 5, 7, 9
    5
    >>> f(3, 10, 0) 
    10
    >>> f(3, 10, 1) # 1, 2, 4, 5, 7, 8, 10
    7
    >>> f(3, 10, 2) # 2, 5, 8
    3
    >>> f(5, 5, 2)
    3
    '''
    if n <= K:
        return 0
    if K == 0:
        return N
    ans = max(N % n - (K - 1), 0)
    ans += N // n * (n - K)
    return ans


def solve(N: int, K: int):
    ans = 0
    for b in range(N+1):
        #print(b, f(b, N, K))
        ans += f(b, N, K)
    return ans


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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
    print(solve(N, K))

def test():
    import doctest
    doctest.testmod()

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

Submission status: Accepted

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

# k=0 -> n*n
if k == 0:
	print(n * n)
	exit()

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

print(cnt)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time

def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
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)]


yn = ['Yes', 'No']
YN = ['YES', 'NO']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    N, K = MI()
    # arr = [[0] * N for i in range(N)]

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

    # for b in range(1, N+1):
    #     for a in range(1, N+1):
    #         arr[b-1][a-1] = a % b

    ans = 0
    for b in range(N):
        if K <= (b + 1) - 1:
            # print(b+1, arr[b])
            loop = N // (b+1)
            r = N % (b+1)
            ans += loop * ((b+1) - K)
            ans += max(0, r - K + 1)
            # print(ans, loop * ((b+1) - K), r - K + 1)
    print(ans)


if __name__ == '__main__':
    main()