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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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


solve()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
b,s=K+1,0
while b <= N:
 c=N%b
 s+=(N//b)*(b-K)+max(0,c-K+1)
 b+=1
print(s if K!=0 else N*N)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
 
b = K + 1
s = 0
while b <= N:
    c = N % b
    s += (N//b)*(b-K) + max(0,c-K+1)
    b += 1

print(s if K != 0 else N*N)

Submission status: Accepted

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

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

b = K + 1
s = 0
while b <= N:
    c = N % b
    s += (N//b)*(b-K) + max(0,c-K+1)
    b += 1

print(s)

Submission status: Accepted

Solution code:
import bisect
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
from operator import mul

import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

ans = 0
if K == 0:
    print(N ** 2)
    exit()
# K < b <= N
for b in range(K + 1, N + 1):
    nk = (N - K)
    bk = (b - K)
    ans += nk // b * bk + min((nk % b) + 1, bk)
print(ans)

Submission status: Accepted

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


def count():
    if k == 0:
        return n * n

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

    return c


print(count())

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import sys
import math
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

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

print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if K==0:
  answer -= N

print(answer)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

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

    for i in range(k + 1, n + 1):
        p, q = divmod(n, i)
        ans += p * (i - k)
        ans += max(q - k + 1, 0)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sub = 0
for i in range(1, n+1):
    s = n//i
    sub += s*(min(i, k))
    sub += min(n%i, max(0, k-1))
print(n**2 - sub)

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):
    p = N//b
    r = 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)
else:
    def Mods(i, N, K): #iで割った余りがK以上のN以下の数
        lim = N//i
        pattern = i - K
        total = lim * pattern
        if N - i * lim < K:
            return total
        else:
            extra = N - i * lim - K + 1
            return total + extra

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

Solution code:
def big(a,b):
    if a >= b:
        return a
    else:
        return b

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

b = 1
while b <= n:
    p = n//b
    ans += p*big(0,b-k)
    r = n%b
    ans += big(0,r-k+1)
    b += 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):
    p, q = divmod(N, b)
    ans += p * (b - K)
    if K:
        ans += max(0, q - K + 1)
    else:
        ans += q
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

# K b = K+1~N,a = ib+K total:sigma((N-k)//b+1)

if K==0:
        print(N*N)
else:
    ans = 0
    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:
# cook your dish here
n,k = map(int,input().split())
ass = 0

for i in range(k+1,n+1):
    jkl = ass
    ass += (i-1)-k+1
    w = (n-(i-1))//i
    if w >= 1:
        ass += ((i-1)-k+1)*w
    r = n-(w+1)*i
    if r >= k:
        ass += r-k+1
    #print(i,ass-jkl)
if k ==0:
    print(n**2)
else:
    print(ass)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

        if p * b > n + 1:
            cnt -= p * b - max((p-1)*b+k, n+1)

        if k == 0:
            cnt -= 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

        if p * b > n + 1:
            cnt -= p * b - n - 1

        if k == 0:
            cnt -= 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

if k == 0 :
	print n*n

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

	print ans

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()))

ans = 0
N, K = getNM()
for i in range(N):
    b = i + 1
    if b > K:
        set = N // b
        ans += set*(b-K)
        rem = N % b
        if K == 0:
            ans -=1
        ans += max(rem-K+1,0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
cnt = 0
for b in range(k + 1, n + 1):
    cnt += n // b * (b - k)
    cnt += max(0, min(n % b, n % b - k + 1))
print(cnt)

Submission status: Accepted

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

def main():
    n, k = map(int, input().split())
    cnt = 0
    for b in range(k + 1, n + 1):
        cnt += count_a(n, k, b)
    print(cnt)

def count_a(n, k, b):
    assert b > k
    fulls = (n + 1) // b
    rest = (n + 1) % b
    cnt = fulls * (b - k)
    cnt += max(0, rest - k)
    if k == 0:
        cnt -= 1
    return cnt

main()

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

	print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n, k = f.read_int_list()
    if k == 0: return n**2
    ans = 0
    for b in xrange(k+1, n+1):
        ans += (n/b)*(b-k)+max(0,n-((n/b)*b+k)+1)
    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
N, K = inpl()

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
if K == 0:
    ans = N**2
else:
    for b in range(1, N+1):#bを動かす、aの個数はわかる
        p, r = N // b, 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(1, N+1):
    block_K = max(0, b-K)
    #print("b", b, "block_num", (N+1)//b, "block_K", block_K, "remain", (N+1)%b)
    ans += block_K * ((N+1)//b) + max(0, (N+1)%b - K)

print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

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


print ans

Submission status: Accepted

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

answer = 0

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

print(answer)

Submission status: Accepted

Solution code:
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft


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()

n, k = LI()

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

    #print("mid: ", counts)

print(counts)

Submission status: Accepted

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

retSum = 0
for b in range(K+1, N+1):
    q = N // b
    r = N - q * b
    if r >= K and r != 0:
        if r == K: retSum += 1
        else:
            if K == 0: retSum += r - K
            else: retSum += r - K + 1
    retSum += q * (b - K)
print(retSum)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(result)

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

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

(N, K) = reads()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys

N,K = map(int, input().split())
res = 0
if K==0:
    print(N*N)
    sys.exit(0)
for i in range(N):
    i += 1
    if i-K<=0:
        continue
    amari = N % i
    amari = amari - K + 1
    re = N // i
    if amari <= 0:
        amari = 0
    res += re*(i-K) + amari
print(res)

Submission status: Accepted

Solution code:
def calc(N, K):
    if K == 0:
        return N**2
    result = 0
    for b in range(K + 1, N + 1):
        n, m = divmod(N, b)
        result += (b - K) * n
        if m >= K:
            result += m - K + 1
    return result

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

Submission status: Accepted

Solution code:
def calc0(N, K):
    r = 0
    for a in range(1, N + 1):
        for b in range(1, N + 1):
            if a % b >= K:
                print(a, b, a % b)
                r += 1
    return r

def calc1(N, K):
    result = 0
    for i in range(K, N):
        for x in range(i + 1, N + 1):
            if i > 0:
                r = (N + x - i) // x
            else:
                r = (N + x - i) // x - 1
            # print(i, x, r)
            result += r
    return result

def calc2(N, K):
    if K == 0:
        return N**2
    result = 0
    for x in range(1, N + 1):
        for i in range(K, min(N, x)):
            r = (N - i) // x + 1
            result += r
    return result

def calc2(N, K):
    if K == 0:
        return N**2
    result = 0
    for x in range(1, N + 1):
        for i in range(K, min(N, x)):
            r = (N - i) // x + 1
            result += r
    return result

def calc3(N, K):
    if K == 0:
        return N**2
    result = 0
    for x in range(1, N + 1):
        st = N - min(N, x) + 1
        ed = N - K
        if (ed < x):
            r = (ed - st + 1)
        else:
            r = 0
            for j in range(st, ed + 1):
                r += j // x + 1
        print(st, ed, x, r)
        result += r
    return result

def calc(N, K):
    if K == 0:
        return N**2
    result = 0
    for b in range(1, N + 1):
        if b <= K:
            continue
        n, m = divmod(N, b)
        r1 = (b - K) * n
        r2 = 0
        if m >= K:
            r2 = m - K + 1
        result += r1 + r2
    return result

N, K = [int(_) for _ in input().split()]
# print(calc2(N, K))
print(calc(N, K))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]
    S = 0
    for b in range(K + 1, N + 1):
        i_max = (N - K)/b
        t = max((i_max * b + (b - 1)) - N, 0)
        S += (((N - K)/b) + 1) * (b-K) - t
    if K == 0:
        S -= N
    print S

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

	k = ((N - K) // b)
	num = min(((N - K) % b) + 1,b-K)
	other = (b - K) - num

	ans += ((b - K) * (k + 1) - other)
	

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

Submission status: Accepted

Solution code:
import sys
n, k = map(int, raw_input().split())
c = 0
if k == 0:
    print n**2
    sys.exit()
for x in xrange(k+1, n+1):
    c += len(xrange(k, x))
    c += ((n-x)/x)*(x-k)
    if (n-x)%x-k+1 > 0:
        c += (n-x)%x-k+1
print c

Submission status: Accepted

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

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, K = list(map(int, input().split(' ')))

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

        print(counter)
    else:
        print(N**2)

Submission status: Accepted

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

Submission status: Accepted

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

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

else:
    for i in range(N):
        row=N-i
        if row <= K or row ==0:
            break
        out += (N-i-K) * int(N/row)
        if N%row >= K:
            out+=N%row-K+1

    print(out)

Submission status: Accepted

Solution code:
num = map(int,raw_input().split())
n = num[0]
k = num[1]

tot = 0

for i in range(n - k):
    s = n / (k + i + 1)
    t = n % (k + i + 1) - k + 1
    if t < 0:
        t = 0
    tot += s * (i + 1) + t

if k == 0:
    tot -= n 
    
print tot

Submission status: Accepted

Solution code:

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

    ans = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            if i % j >= k:
                ans += 1
    print(ans)


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

    # k0は例外処理
    if k == 0:
        print(n**2)
        return

    # 割る数Bを増やしながら考える
    # b<=kまでは、割る数がk以下なのであまりは絶対kを超えない
    # K<b以降（b=k+1～n）
    ans = 0
    for b in range(k+1, n+1):
        n_iter = (n+1)//b
        amari = (n+1) % b

        #print(n_iter, b, k, n_iter*(b-k), amari, max(0, amari-k))
        ans += n_iter * (b-k)
        ans += max(0, amari-k)

    # B>=Kのところ
    # どうやってもあまりはK以上にならないので数えない

    print(ans)

solve()

Submission status: Accepted

Solution code:
import numpy as np

n, k = map(int, input().split())
ans = 0
for m in range(k, n):
    nm = n - m
    sb = m + 1
    s = nm // sb
    p = s + 1 if m else s
    ps = sb
    for d in range(s, 0, -1):
        ds = nm // d + 1
        co = ds - ps
        ans += co * p
        ps = ds
        p -= 1
    ans += n + 1 - ps

    # ds = [nm // d + 1 for d in range(s, 0, -1)]
    # ds = [sb] + ds + [n + 1]
    # # print(m, nm, sb, s, ds)
    # dd = np.diff(ds)
    # pd = np.arange(s + 1, 0, -1) if m else np.arange(s, -1, -1)
    # # print(dd, pd, dd * pd, sum(dd * pd))
    # ans += sum(dd * pd)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import math


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

    if K == 0:
        return N * N

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

    return ans


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, K = rdi()

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

s = 0
for b in range(K+1, N+1):
        an = 0
        j = N / b
        an = j * (b - K)
        #print b, an
        if N % b > 0:
                x1 = j * b + K
                if K == 0:
                        x1 += 1
                x2 = min(N, (j+1) * b - 1)
                #print b, x1, x2
                if x2 >= x1:
                        an += (x2 - x1 + 1)
        s += an
        #print b, an
print s

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

print(ans)