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:
    ans = n ** 2
else:
    for b in range(k + 1, n + 1):
        ans += (b - k) * (n // b)
        last_count = n % b - k + 1
        ans += last_count if last_count > 0 else 0

print(ans)

Submission status: Accepted

Solution code:
n,k=[int(i) for i in input().split()]
ans=0
left=[i+1 for i in range(n)]
right=[i+1 for i in range(k, n)]
amari=[0 for i in range(k, n)]

for i in range(len(amari)):
    amari[i]=(n//right[i])*(right[i]-1)-(n//right[i])*(k-1) + max(0,n%right[i]-(k-1))

if k==0:
    print(n**2)
else:
    print(sum(amari))

Submission status: Accepted

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

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def d_remainder_reminder(N, K):
    if K==0:
        return N*N
    import bisect
    ans = 0
    for b in range(K + 1, N + 1):
        tmp1 = (N+1)//b #[0,1,2,...,b-1]のパターン何個
        tmp2 = (N+1)%b #[0,1,...,途中]のパターン
        # print(tmp1,tmp2)

        t=0 if tmp2<=K else tmp2-K
        ans += (b-K)*tmp1 + t
        # print(ans)
    return ans 

N,K = [int(i) for i in input().split()]
print(d_remainder_reminder(N, K))

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
x = 0
if K == 0:
    x = N*N
else:
    for i in range(N-K):
        A = K+1+i
        x += (A-K)*(N // A)
        T = (N%(A-K))-K+1
        if  T > 0:
            x += T

print(x)

Submission status: Accepted

Solution code:
import sys 

temp=input().split(" ")
n=int(temp[0])
k=int(temp[1])
count=0
for b in range(k+1,n+1):
    temp=int(n/b)
    count+=temp*(b-k)

    temp=n%b
    if (temp-k+1)>0:
        count+=(temp-k+1)
if k==0:
    count-=n


print(count)

Submission status: Accepted

Solution code:
NK= list(map(int,input().split()))
a = NK[1]
b = NK[1]+1
if NK[1] == 0:
    a = 1
    b = 1
temp = 0
while a <= NK[0]-1:
    temp += (NK[0]-a)
    a+=1
while b <= (NK[0]-NK[1]):
    step = int(NK[0]/b)
    cross = b-NK[1]
    temp += (step-1)*cross
    if (b*step + NK[1]) < NK[0]:
        temp += (NK[0]+1-(b*step + NK[1]))
    if (b*step + NK[1]) == NK[0]:
        temp += 1
    b+=1

print(temp)

Submission status: Accepted

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


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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

for b in range(k+1,n+1):
  # for a in range(k,n+1,b):
    # 0,1,...,  k,     k+1, k+2...,   b-1
    # b,b+1,... b+k, b+k+1, ...   ,   b+b-1
    # ........     , n
    buf = b-k
    buf2 = n/b
    buf = buf * buf2
    #print buf
    buf3 = buf2*b
    #print buf3
    if (n - buf3 - k + 1) > 0:
      buf += (n - buf3 - k + 1)
    ans += buf
    #print b,buf
    # and if 
print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nk = input().split()
n = int(nk[0])
k = int(nk[1])

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

        

print(cnt)

Submission status: Accepted

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

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

if K == 0:
    count -= len(range(K + 1, N + 1))

print (count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# C

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

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

ans = 0
for i in range(1, N - K + 1):
    b = K + i
    x = int((N - K) / b)
    M = min(N, K + x*b + i - 1)

    ans += i*x + M - (K + x*b) + 1

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ans = 0
for b in range(N + 1)[K:]:
	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: Runtime Error

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
10 0def 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: Runtime Error

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

Submission status: Runtime Error

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

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

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

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


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

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = input()
K = input()
N = int(N)
K = int(K)
sum = 0
if K == 0:
    print(N ** 2)
else:
    for i in range(K, N + 1):
        for j in range(K, N + 1):
            if j % i >= K:
                sum += 1
            j += 1
        i += 1
    print(sum)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:

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


ans = 0

# N = pb + r

for b in range(k+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(

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = 0
    if K == 0:
        print(N * N)
        break
    for i in range(1, N+1):
        if i <= K:
            continue
        if N % i < K:
            ans += (N // i) * (i - K)
        else:
            ans += (N // i ) * (i - K) + (N % i - K + 1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


int main()
{
    int N, K;
    cin >> N >> K;

    int ans = 0;
    if( K == 0 )
    {
        for( int b = 1; b <= N; ++b  ) ans += N / b;
        for( int reminder = 1; reminder < N; ++reminder ){
            for( int b = reminder+1; b <= N; ++b  ){
                ans += ( N - reminder ) / b + 1;
            }
        }
    }
    else
    {
        for( int reminder = K; reminder < N; ++reminder ){
            for( int b = reminder+1; b <= N; ++b  ){
                ans += ( N - reminder ) / b + 1;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
n, k = list(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)
        ans += max(0, (n - (n // b * b)) - k + 1)

print(ans)

Submission status: Runtime Error

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

if k == 0:
    print(n**2)
else:
	total = 0
    for i in range(k+1,n+1):
        d,m = divmod(n,i)
        
        if (i-k) > 0:
            total += d*(i-k)
        if (m-k+1) > 0:
            total += m-k+1

    print(total)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int N,K;
long long ans;
int main(){
    cin>>N>>K;
    for(int i=K+1;i<=N;i++){
        ans+=N/i*(i-K)+max(N%i-K+1,0);
    }
    if(K==0)ans-=N;
    cout<<ans<<'\n';
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
count=0
for i in range (1,N+1):  #a
    for j in range (1,N+1): ##b
        if i%j>=K:
            count=count+1
print (count)

Submission status: Runtime Error

Solution code:
count = 0
for b in range(K+1, N+1):
        count += (b-K)*int((N-b+1)/b)


if K != 0:
    for a in range(K, N+1):
        count += N-a
if K == 0:
        for a in range(1, N+1):
            count += N-a

print(count)

Submission status: Runtime Error

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

count = 0

for a in range(1, N_K+1[0]):
  for b in range(1, N_K+1[0]):
    if a % b >= N_K[1]:
      count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

/*<ここから>***********************************************************/


int main()
{
	int N, K;
	cin >> N >> K;

	int ans = 0;
	repr(i, 1, N + 1) {
		ans += N / i * max(0, i - K);
		ans += max(0, N % i - K + 1);
	}

	cout << ans << endl;

	return 0;
}

Submission status: Runtime Error

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

cnt = 0


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

Submission status: Runtime Error

Solution code:
    data = input()
    data = data.split(" ")
    n = int(data[0])
    k = int(data[1])
    sum = 0
    for b in range(1, n+1):
        sum += (n//b*max(0,b-k)+max(0,n%b-k+1))
    if k == 0: sum-=n
    print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

count = 0

for a in range(1, n+1):
    for b in range(1, n+1):
        if a % b >= k:
            count += 1
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def solve(n,k):
  counter = 0
  for i in range(n,k,-1):
    theValue = n//i * (i-k) + max(n%i-k , 0)
    counter += theValue
  return counter

c = list(map(int, input().split(' ')))
def(c[0], c[1])

Submission status: Runtime Error

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

	ans = 0

	for i in range(K, N+1):
		for j in range(K, N+1):
			if i%j >= K:
				ans +=1

	print (ans)

"""			
			if a not in dic.keys():
				dic.update({a:1})
			else:
				val = dic.get(a)
				val += 1
				dic.update({a:val})
				count += 1

		if count ==3:
			ans += 1

		if (len(dic.keys())) == 3 and count ==2:
			ans += 1

		if n == 11111:
			print (count)
"""

if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Submission status: Runtime Error

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