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

i = K + 1

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K=[int(i) for i in input().split()]

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

#nnn=0
#for a in range(1,N+1):
#    for b in range(1,N+1):
#        if a%b >= K:
#            nnn+=1
#print(nnn)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def f(b, K, N):
    i = N // b
    ans = N - ((K-1) + (i - 1) * K + min((N%b) + 1, K))
    return ans

N, K = map(int, input().split(' '))
if K == 0:
    ans = int(N * N)
    print(ans)
else:
    ans = 0
    for b in range(K+1, N+1):
        ans += f(b, K, N)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = input().split(" ")
N = int(l[0])
K = int(l[1])
ts = 0
for b in range(K + 1, N + 1):
  ts += (N // b) * (b - K) \
      + max(0, N % b - K + 1)
  if K == 0:
    ts -= 1
print(ts)

Submission status: Accepted

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

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def 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 pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    if k == 0:
        return n*n
    r = 0
    for b in range(k+1,n+1):
        t = b - k
        u = n // b
        a = t * u
        a += max(0, n - (u * b + k - 1))
        r += a

    return r


print(main())

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
b=[i for i in range(k+1,n+1)]
ans=0
if k==0:
    for i in range(len(b)):
    t=b[i]
    j=t-k
    ii=n//t
    ans+=ii*j
    ans+=max(n-ii*t-k,0)
    print(ans)
    exit()
for i in range(len(b)):
    t=b[i]
    j=t-k
    ii=n//t
    ans+=ii*j
    ans+=max(n-ii*t-k+1,0)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
,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: Runtime Error

Solution code:
#include<iostream>
using namespace std;

int main() {
    int N, K;
    cin>>N>>K;
    int ans = 0;
    for(int b=K+1;b<=N;++b){
        ans += N/b*(b-K);
        if((N%b)-(K-1) > 0) ans += (N%b) - (K-1);
    }
    if(K==0)ans -= N-K;
    cout<<ans<<endl;
}

Submission status: Runtime Error

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

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: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

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:
        result -= n
    print(result)
main()

Submission status: Runtime Error

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,n+1)))

Submission status: Runtime Error

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== else ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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 -= 10
print(res)

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

Solution code:
N,K = map(int, input().split())
res = 0
if K==0:
    print(N*N)
    return
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)