Floor and Mod (Codeforces 1485C)
Tags: Math, number theory

A pair of positive integers $$$(a,b)$$$ is called special if $$$\lfloor \frac{a}{b} \rfloor = a \bmod b$$$. Here, $$$\lfloor \frac{a}{b} \rfloor$$$ is the result of the integer division between $$$a$$$ and $$$b$$$, while $$$a \bmod b$$$ is its remainder.You are given two integers $$$x$$$ and $$$y$$$. Find the number of special pairs $$$(a,b)$$$ such that $$$1\leq a \leq x$$$ and $$$1 \leq b \leq y$$$.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.The only line of the description of each test case contains two integers $$$x$$$, $$$y$$$ ($$$1 \le x,y \le 10^9$$$).

Output: For each test case print the answer on a single line.

Note: In the first test case, the only special pair is $$$(3, 2)$$$.In the second test case, there are no special pairs.In the third test case, there are two special pairs: $$$(3, 2)$$$ and $$$(4, 3)$$$.

Sample Inputs:
9
3 4
2 100
4 3
50 3
12 4
69 420
12345 6789
123456 789
12345678 9

Sample Outputs:
1
0
2
3
5
141
53384
160909
36

Solution (Python):
import sys
input = sys.stdin.readline
import math as m

def solve():
    (x, y) = map(int, input().split())
    answer = 0
    k = 1
    while min((x - k) // k, y) - k > 0:
        answer += min((x - k) // k, y) - k
        k += 1
    print(answer)
for _ in range(int(input())):
    solve()

Solution (Python):
from math import gcd
import os
import sys
from io import BytesIO, IOBase

def arr_input():
    return list(map(int, input().split()))

def mul_input():
    return map(int, input().split())

def int_inp():
    return int(input())

def solution():
    (x, y) = mul_input()
    ans = 0
    ans = 0
    val = 1
    while val < y:
        v = x // val - 1
        if v <= val:
            break
        if v <= y:
            ans += max(0, v - val)
        else:
            ans += max(0, y - val)
        val += 1
    print(ans)
    return

def main():
    testcases = 1
    testcases = int(input())
    for _ in range(testcases):
        solution()
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            (self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda : self.buffer.read().decode('ascii')
        self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
    return sys.stdin.readline().rstrip('\r\n')
if __name__ == '__main__':
    main()

Solution (Python):
""""""
import sys
input = sys.stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())

def solve():
    (x, y) = R()
    ans = 0
    i = 1
    while i * i <= x:
        temp = min(y, x // i - 1) - i
        ans += 0 if temp < 0 else temp
        i += 1
    print(ans)
for _ in range(I()):
    solve()