Problem:


Score : 400 points

Problem Statement

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

Constraints

1 \leq N \leq 10^5

0 \leq K \leq N-1

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

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

Sample Input 1

5 2

Sample Output 1

7

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

Sample Input 2

10 0

Sample Output 2

100

Sample Input 3

31415 9265

Sample Output 3

287927211



Sample input:
5 2


Sample output:
7

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans if K > 0 else ans - N)

Submission status: Accepted

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
cnt=0
if K==0:
    print(N*N)
else:
    for i in range(K+1,N+1):    #bの数について
        fin=N%i
        if (fin>=K):
            cnt=cnt+(fin-K)+1
        clus=(N-fin)//i
        cnt=cnt+clus*(i-K)
        #print(cnt)
    print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    if k == 0:
        print(n ** 2)
        exit()
    cnt = 0
    for i in range(1, n+1):
        p, r = divmod(n, i)
        cnt += max(0, p * (i - k)) + max(0, r - k + 1)
    
    print(cnt)
if __name__=='__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
for b in range(k+1,n+1):
  r=n%b
  q=n//b
  ans+=(b-k)*q+max(r-max(k-1,0),0)
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):
    div=n//b  
    ans+=(b-k)*div
    rem=n%b
    ans+=max(0,rem-k+1)
print(ans)

Submission status: Accepted

Solution code:
# solution

import io
import sys
import math

nim, mike = map(int, input().split())

if mike==0:
    print(nim*nim)
    exit()

b = mike+1

counter = 0

while b<=nim:
    counter += (nim//b)*(b-mike)+max(nim%b-mike+1, 0)
    b += 1

print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
from math import floor

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

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

ans = 0
for b in range(1, N + 1):
    # [1, N]をbで割る
    num = N // b
    rem = N % b
    # numの中がK以上である個数
    # あまり: 0, 1, 2, ..., b - 1
    fact = b - 1 - K + 1
    if fact > 0:
        ans += num * fact
    
    # 残った分
    ans += max(0, rem - K + 1)
    # print(b, num, rem, num * fact, rem)
print(ans)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

co = 0

n,k = m()

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

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
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for b in range(1,N+1):
    p = N//b
    ans += p*max(b-K,0)
    r = N % b
    ans += max(r-K+1,0)
if K == 0:
    ans = N**2
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc090/tasks/arc091_b
# 15:26-


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

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

    return ans


print(main())

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,K = map(int,input().split())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from heapq import heapify, heappop, heappush

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

N, K = MAP()

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

Submission status: Accepted

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


def solve(N: int, K: int):
    print(sum(
        N // b * (b - K) + max(0, N % b - max(0, K - 1))
        for b in range(K + 1, N + 1)
    ))


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:
def main():
    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
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    s = 0
    if k==0:
        s = n*n
    else:
        for k_ in range(k,n):
            for q in range((n-k_)//(k_+1)+1):
                if q==0:
                    s += n-k_
                else:
                    s += (n-k_)//q-k_
    print(s)
            
if __name__ == "__main__":
    main()

Submission status: Accepted

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

    count += x
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
for j in range(K+1, N+1):
    block = N // j
    R = N % j
    cnt += block * (j-1-K+1)
    if R:
        cnt += max(0, R - max(K,1) +1)
    #print(j, block, block * (j-1-K+1), max(0, R - K +1))
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

    ans += max(0, val - max(0,(k-1)))
    #print(ans)
print(ans)

Submission status: Accepted

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

def main():
    ans = 0
    if k!= 0:
        for b in range(k+1,n+1):
            for q in range((n-k)//b+1):
                ans += min(b-k,n-b*q-k+1)
        print(ans)
        return
    else:
        print(n*n)
        return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
if k==0:
    ans=n*n
else:
    #count a<b cases 
    for b in range(k+1,n+1):
        ans+=b-1-k+1
    #count a>b cases 
    for b in range(k+1,n+1):
        #from b+k to b+b-1 mod>=k after that cycle repeats
        steps=(n-b+1)//b
        ans+=steps*(b-k)
        rem=(n-b+1)%b
        if rem>k:
            ans+=rem-k
print(ans)

Submission status: Accepted

Solution code:

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

    b = k + 1
    ans = 0
    while b <= n:
        # bを固定した時にあまりがk以上になるaの数を求める
        block = (n + 1) // b
        rest = (n + 1) - block * b
        ans += (b - k) * block
        ans += max(0, rest - k)
        if k == 0:
            ans -= 1
        b += 1
    print(ans)


submit()

Submission status: Accepted

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

ans = 0

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

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

Submission status: Accepted

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

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

answer = 0
for i in range(k + 1, n + 1):
    q = n // i; r = n % i
    answer += (i - k) * q
    if r >= k:
        answer += r - k + 1

print(answer)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

if K == 0:
    print(N * N)
else:
    ans = 0
    for i in range(K + 1, N + 1):
        cnt = N // i
        x = max(0, N - cnt * i - K + 1)
        ans += (cnt + 1) * x
        ans += cnt * (i - K - x)
        # for j in range(K, i):
        #
        #     if cnt * i + j <= N:
        #         cnt += 1
        #     ans += cnt
        # print(i, cnt, x, ans)
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if k == 0:
    count -= n
print(count)

Submission status: Accepted

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

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

#print(*ans, sep='\n')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for b in range(K + 1, N + 1):
    x, y = divmod(N, b)

    k = b - K
    cnt += k * x - (K == 0) + max(0, y - (K - 1))

print(cnt)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
#090_D
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))
print(ans if k > 0 else n ** 2)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    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__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

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

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

Submission status: Accepted

Solution code:
lim, pol = map(int,input().split())

count = 0
num = 0
if pol == 0:
    count = lim * lim
else:
    for kk in range(pol, lim + 1):
        num = (lim - lim % kk) / kk
        count += (kk - pol) * num
        if lim % kk >= pol:
            count += lim % kk - pol + 1

print(int(count))

Submission status: Accepted

Solution code:
'''
全体からKよりも小さくなる組を引く
(1~N)%iのあまりについて考える。(iは固定)
0<=i<=Kの時、あまりは必ずK-1以下になる(2で割ると余りは[0,1]、3で割ると余りは[0,1,2]、....、Kで割ると余りは[0,1,..,K-1])
i>Kの時、
まず、(1~i)%iについて考える
    ①(1~K-1)%iの余りはK-1以下、個数は(K-1)個     (例:i=K+5の時、1%(K+5)=1、2%(K+5)=2、......、(K-1)%(K+5)=K-1)
    ②(K~i-1)%iの余りはK以上、個数は(i-K)個    (例：i=K+5の時、(K)%(K+5)=K、(K+1)%(K+5)=K+1、.....、(K+4)%(K+5)=K+4)
    ③i%iの余りは0、個数は1個      (例:i=K+5の時、(K+5)%(K+5)=0)

    全部合わせてi個
    このうち、余りがKよりも小さくなるのはK個

では、(i+1~N)%iも上と同様に考える(余りは周期的に繰り返される)と、(N//K)回繰り返されるので、(N//i)*K
あとは余りのところを考えて、min(K-1,N%i)   (maxの部分はK=0対策)
i>Kにおいてはこの和をansから引けば良い。
'''

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for b in range(K,N+1):
    if b==0:
        continue
    #aの数
    #N=pb+r
    #0<=r<bをp回ループした後、r個 or r+1個の余りがある
    #(b-K)でK<=r<bを表している
    #(N//b)でループ数を表している
    ans += (b-K)*int(N//b)

    if N%b>=K and K>0:
        #
        ans+=N%b-K+1
    #K=0のときのみ発動
    elif N%b>=K:
        ans+=N%b
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
for b in range(K,N+1):
    if b==0:
        continue
    #aの数
    #N=pb+r
    #0<=r<bをp回ループした後、r個 or r+1個の余りがある
    #(b-K)でK<=r<bを表している
    #(N//b)でループ数を表している
    ans += (b-K)*int(N//b)

    if N%b>=K and K>0:
        #
        ans+=N%b-K+1
    elif N%b>=K:
        ans+=N%b 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
# 割る値bを固定して該当するaの個数を足し上げる
for b in range(k+1, n + 1):
    q = n // b
    r = n % b
    if r < k:
        ans += q * (b-k)
    else:
        ans += q * (b-k) + (r-k+1)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

cnt = 0

for i in range(1, N + 1):
    if i <= K:
        continue
    a = i - K # 1周期でのK以下の個数
    b = N // i # 何周期あるか
    c = N % i # 周期の余り(1~c)

    cnt += a * b
    if c >= K:
        cnt += c - K + 1

print(cnt)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
class Solution:

    def solve(self, N: int, K: int) -> int:

        if K == 0:
            return N**2

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

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

        return answer


if __name__ == '__main__':

    # standard input
    N, K = map(int, input().split())
    # solve
    solution = Solution()
    print(solution.solve(N, K))

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# aで1~Nまでの数を割っていったときにK以下はいくつあるか？


def f(a, n, k):
    syou, amari = divmod(n, a)
    one_syou = max(a - k, 0)
    plus = max(amari+1 - k, 0) if k != 0 else amari
    # print(syou, amari, one_syou, plus)
    return syou * one_syou + plus


ans = 0
for a in range(max(K, 1), N+1):
    ans += f(a, N, K)
    # print(a, f(a, N, K))

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# aで1~Nまでの数を割っていったときにK以下はいくつあるか？


def f(a, n, k):
    syou, amari = divmod(n, a)
    one_syou = max(a - k, 0)
    plus = max(amari+1 - k, 0) if k != 0 else amari
    # print(syou, amari, one_syou, plus)
    return syou * one_syou + plus


ans = 0
for a in range(1, N+1):
    ans += f(a, N, K)
    # print(a, f(a, N, K))

print(ans)

Submission status: Accepted

Solution code:
def main():
    limit, remainder_min = map(int, input().split(" "))
    answer = 0
    if remainder_min:
        for i in range(1, limit + 1):
            answer += max(0, i - remainder_min) * (limit // i) + max(0, limit % i - remainder_min + 1)
    else:
        answer = limit ** 2
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
total = 0
if not K:
    print(N ** 2)
    quit()

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

print(total)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

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

Submission status: Accepted

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

ans=0
for b in range(K+1,N+1):
    quo=N//b
    ans+=quo*(b-K)
    rem=N-(b*quo+K-1)#途中までの
    if rem>0:
        ans+=rem

if K==0:
    ans-=N-K#a=0(商０かつ余り0)をカウントしているので
        
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline

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

INF = 1e10

N, K = [int(_) for _ in input().split()]


def f(b):
    """
    a= b*x + r
    a=[0,N] まで回すとき, あまり r は 0,1,...,b-1 と順番に出現する. (x = a//b)
    """
    p = (N // b)  # r が p 回 [0,b-1] をループ
    ans = max(p * (b - K), 0)

    # 残りの分
    ans += max(N % b - K + 1, 0)

    if K == 0:
        ans -= 1

    return ans

def main():
    ans =0
    for b in range(1,N+1):
        ans+=f(b)
    print(ans)
main()

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    cnt = 0
    if K == 0:
        print(N * N)
        return

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

main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k = map(int,readline().split())
ans = 0
if k == 0:
    print(n**2)
    exit()
for b in range(1,n+1):
    if b <= k:
        continue
    #a=nとして考えて良い。
    ans += n//b*(b-k)
    ans += max(0,n%b-(k-1))

print(ans)