Problem:


Score : 400 points

Problem Statement

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

Constraints

1 \leq N \leq 10^5

0 \leq K \leq N-1

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

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

Sample Input 1

5 2

Sample Output 1

7

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

Sample Input 2

10 0

Sample Output 2

100

Sample Input 3

31415 9265

Sample Output 3

287927211



Sample input:
5 2


Sample output:
7

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# N=pb+r

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

  for b in range(1,n+1):
    if b<k:
      continue

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

  if k==0:
    ans-=n
  return ans

# main()
print(main())

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

Submission status: Accepted

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

ans = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n,k = map(int,stdin.readline().rstrip().split())
point = 0
#n=p*b+r
for b in range(1,n+1):
    p = n//b
    r = n%b
    point += p*max(0,b-k)
    point += max(0,r-k+1)
if k == 0:
    point -= n
print(point)

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

Submission status: Accepted

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

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

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

    nokori = n-b*num
    if nokori-k+1 > 0:
       add+= nokori - k+1

#    print("  ",b,num,add)
    ans+=add
print(ans)

Submission status: Accepted

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

for b in range(1,n+1):
    p=n//b
    r=n-p*b

    if b-1>=k:
        cnt+=p*(b-k)+max(r-k+1,0)
        #print(cnt,num)
print(cnt)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,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
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
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()
    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:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
res = 0
for x in range(K + 1, N + 1):
  res += (N // x) * (x - K) + max(0, N % x - K + (K > 0))
  #print(x, res)
print(res)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

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

ans = 0
for n in range(N + 1):
    # 無理
    if n <= K:
        continue

    if K == 0:
        ans += N
        continue

    # 倍数分
    ans += (N // n) * (n - K)
    # あまり分
    if K <= (N % n):
        ans += (N % n) - 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):
    ans += n//b * (b-k)
    ans += max((n%b)-k+1, 0)
if k == 0:
    # ans -= n
    ans = 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)
    ans += max((n%b)-k+1, 0)
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):
    ans += (N//b)*max(0,b-K) + max(0,N%b-K+1)
if K == 0:
    ans -= N
print(ans)

Submission status: Accepted

Solution code:
def examC():
    N = LI(); N.sort()
    if N[0]==1:
        if N[1]==1:
            ans = 1
        else:
            ans = max(0,N[1]-2)
    else:
        ans = (N[1]-2)*(N[0]-2)
    print(ans)
    return

def examD():
    N, K = LI()
    ans = 0
    b = K+1
    while(b<=N):
        cur = N//b * (b-K) + max(0,N%b - K+1)
        if cur==N+1:
            cur = N
        ans += cur
        b += 1
#        print(ans)
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

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 SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def f(x, y):
    a, b = divmod(x,y)
#    print("aa",b*(a+1))
    return y*a*(a+1)//2 + (b+1)*(a+1)

r = 0
for b in range(K+1, N+1):
#    print(f(N-K, b), f(N-b, b))
    r += f(N-K, b)- f(N-b, b)
    if K == 0:
        r -= 1
#    print(b, N-b+1, N-K+1)
#    print(b, (N-K)//b, (N-b)//b, (N-K)%b, (N-b)%b, b-K)
#    for j in range(N-b+1,N-K+1):
#        r += j//b + 1
print(r)

Submission status: Accepted

Solution code:
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/apc001/tasks/apc001_c
# C - Vacant Seat
"""
m > n impossible
m = n, possible only when n = 1


"""

N = gi()
K = gi()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, 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:
    print(n**2)
    quit()
for b in range(k+1,n+1):
    cnt = 0
    cnt += (b-1)-(k-1)
    cnt += (n-(b-1))//b * (b-k)
    cnt += max(0, (n-(b-1))%b-k)
    res += cnt
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
res = 0
for i in range(1, N + 1):
  u = max(i - K, 0)
  v = N // i
  x = max(N % i - K + 1, 0)
  res += u * v + x - (K == 0)
  #print(i, u, v, x)
  #print(res)
print(res)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
#N=10
#K=0
s=0

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

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, K = rl()
answer = 0
if K == 0:
    print(N**2)
    exit()
for b in range(K+1, N+1):
    x = N // b
    answer += x * (b-K) + max(0, (N-(x*b))-K+1)
    #print(answer)

print(answer)
#59

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for i in range(k+1,n+1):#iは割る数
  num=i-k#k以上のあまりの種類
  c=n//i
  ans+=num*c#(c-1)~0まであまりがk~i-1
  r=n%i
  if r<k:
    pass
  else:
    ans+=r-k+1
if k==0:
  print(ans-n)
  exit()
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,k=inpm()
    ans = 0
    for b in range(k+1,n+1):
        x=n//b
        y=n%b
        a=x*(b-k)+max(0,y-k+1)
        ans+=a
    if k==0:
        ans-=n
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n,k  =(int(i) for i in input().split())
  if n <= k:
    print(0)
    exit()
  else:

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    if K == 0:
        cnt -= N

    print(cnt)


if __name__ == "__main__":
    main()

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:
        ans+=n%i-k+1
print(ans)

Submission status: Accepted

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

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

    print(res)


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

Submission status: Accepted

Solution code:
import sys
n, k = [int(i) for i in sys.stdin.readline().split()]
cnt = 0
for i in range(k+1, n+1):
    larger = n // i
    amari = n % i
    cnt += larger * (i - k) + max(0, amari - k + 1) if k != 0 else larger * (i - k) + amari
print(cnt)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#scipy.sparse import csr_matrix
#scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
    N,K=map(int,input().split())
    ans=0
    for i in range(K+1,N+1):
        ans+=(N//i)*(i-K)+max((N%i-max(K,1)+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):
    tmp1 = max(0, n//i * (i-k))
    tmp2 = max(n%i+1-k, 0)
    ans += tmp1 + tmp2

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	ans = 0
	for i in range(K + 1, N + 1):
		ans += (N // i) * (i - K)
		if N % i >= K and N % i != 0:
			ans += N % i - K + 1

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


if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = 0
for b in range(1, N + 1):
    able_div = N // b
    able_div_nums = able_div * max(0, b - K)
    remainders = max(0, (N % b) - K + 1)
    #print(f'able_div_nums: {able_div_nums}')
    #print(f'remainders: {remainders}')
    ans += able_div_nums + remainders
print(ans)

Submission status: Accepted

Solution code:
# 2019/10/02

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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)  # 繰り返される部分
    ans += max(0, r - K + 1)  # 最後に付け加えられる部分

if K == 0:
    # 1~NのN回 b に関する演算を行なっているから -N
    ans -= N  # 各bに対して,本来許されない a=0 をカウントしてしまっているから帳尻合わせをする

print(ans)

Submission status: Accepted

Solution code:
import math
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
N,K = map(int,input().split())
ans = 0
if K == 0:
    print(N**2)
else:
    for b in range(K+1,N+1):
        chk1 = N%b
        chk2 = N//b
        ans += (b-K)*chk2+max(0,chk1-K+1)
    print(ans)

Submission status: Accepted

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

count = 0
for b in range(max(k,1),n+1):
    if n % b != 0:
        t = math.ceil(n/b)
    else:
        t = int(n/b) + 1
    if n % b >= k:
        count += (b-k)*t - ((t*b-1)-n)
    else:
        count += (b-k)*(t-1)

#k=0のとき,n=0を除外する
if k ==0:
    count -= (n-k)


print(count)

Submission status: Accepted

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

# a = b * x + K
# bを固定してaを1~Nまで動かしたとき、aをbで割った余りは1,2...b-1,0のb通り。
# その中にK以上の余りはb-K通り。
# 余りを順に並べると、1,2...b-1,0,1,2...b-1,0,1,2...N%b となる。
# 1,2...N%b の中にK以上の数はN%b-K+1通り。
# 1,2...b-1,0はN//b回繰り返される。
# Kが0のときは、a,bはどんな組み合わせでもいいからN**2通り。

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

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
#%%
cnt = 0
if(K==0):
    print(N**2)
else:
    for i in range(K+1,N+1):
        x = i-K
        y = N // i
        cnt += x*y + max(0,N%i-K+1)
    print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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:
import sys
input = sys.stdin.readline

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

    print(count) if K != 0 else print(count-N)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

sum=0

for i in range(K+1,N+1):
    sum+=(N//i)*(i-K)+max(0,N%i-K+1) #バルクと表面
    
if K==0:
    sum-=N
    
print(sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit, stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
if K == 0:
    print(N*N)
    exit()
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:
# ARC091D - Remainder Reminder
def main():
    N, K = tuple(map(int, input().split()))
    if K == 0:
        print(N ** 2)
    else:
        ans = sum(
            N // i * (i - K) + max(0, (N % i) - K + 1) for i in range(K + 1, N + 1)
        )
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(N: int, K: int):
    # a, b <= N
    # a % b >= K
    res = 0
    for b in range(K+1, N+1):
        m, r = divmod(N, b)
        res += N + 1
        if K == 0:
            res -= 1
        res -= m * K # 0 ~ m*b-1
        res -= min(r+1, K) # m*b ~ m*b+r (=N)
    print(res)
    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())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

c = 0

for i in range(K+1,N+1) :
    c += 1
    d = min(N,N-(K-1))

    while d > 0 :
        ans += min(d,c)
        d -= c
        d -= K

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, k = li()

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

if k == 0:
    ans -= n

print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np


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


main()

Submission status: Accepted

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