Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend to be sad, so he would ensure to give at least one sweet to each friend. 

He wants to celebrate it in a unique style, so he would like to ensure following condition for the distribution of sweets. Assume that he has distributed n sweets to his friends such that i^{th} friend is given a_{i} sweets. He wants to make sure that there should not be any positive integer x > 1, which divides every a_{i}.

Please find the number of ways he can distribute sweets to his friends in the required way. Note that the order of distribution is important, for example [1, 2] and [2, 1] are distinct distributions. As the answer could be very large, output answer modulo 1000000007 (10^9 + 7).

To make the problem more interesting, you are given q queries. Each query contains an n, f pair. For each query please output the required number of ways modulo 1000000007 (10^9 + 7).


-----Input-----

The first line contains an integer q representing the number of queries (1 ≤ q ≤ 10^5). Each of the next q lines contains two space space-separated integers n, f (1 ≤ f ≤ n ≤ 10^5).


-----Output-----

For each query, output a single integer in a line corresponding to the answer of each query.


-----Examples-----
Input
5
6 2
7 2
6 3
6 4
7 4

Output
2
6
9
10
20



-----Note-----

For first query: n = 6, f = 2. Possible partitions are [1, 5] and [5, 1].

For second query: n = 7, f = 2. Possible partitions are [1, 6] and [2, 5] and [3, 4] and [4, 3] and [5, 3] and [6, 1]. So in total there are 6 possible ways of partitioning.

Difficulty: HARD
Tags: Dynamic programming

Combinatorics

Mathematics
Skill types: Dynamic programming

Starter code:

Solutions:
import itertools
import functools
import operator
N = 100001
P = 10 ** 9 + 7
fact = [1]
for i in range(1, N):
	fact.append(fact[-1] * i % P)
inv = [0, 1]
for i in range(2, N):
	inv.append(P - P // i * inv[P % i] % P)
inv_fact = [1]
for i in range(1, N):
	inv_fact.append(inv_fact[-1] * inv[i] % P)
least_div = [-1] * N
primes = []
for p in range(2, N):
	if least_div[p] == -1:
		primes.append(p)
		least_div[p] = p
	ldiv = least_div[p]
	for mult in primes:
		mark = mult * p
		if mult > ldiv or mark >= N:
			break
		least_div[mark] = mult
t = int(input())

def powerset(iterable):
	s = list(iterable)
	return itertools.chain.from_iterable((itertools.combinations(s, r) for r in range(len(s) + 1)))

@functools.lru_cache(maxsize=None)
def factor(n):
	ret = []
	while n != 1:
		tmp = least_div[n]
		if not (ret and ret[-1] == tmp):
			ret.append(tmp)
		n //= tmp
	return ret

@functools.lru_cache(maxsize=None)
def solve(n, k):
	divs = factor(n)
	ret = 0
	for subset in powerset(divs):
		div = functools.reduce(operator.mul, subset, 1)
		if n // div >= k:
			tmp = fact[n // div - 1] * inv_fact[n // div - k] % P * inv_fact[k - 1] % P
			ret += (-1 if len(subset) % 2 == 1 else 1) * tmp
			ret %= P
	return ret
for _ in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


import os
import sys
from io import BytesIO, IOBase
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from itertools import combinations

def ncr(n, r):
	return f[n] * fi[r] * fi[n - r] % m
f = [1] * 100001
fi = [1] * 100001
a = 1
m = 10 ** 9 + 7
for i in range(1, 100001):
	a *= i
	a %= m
	f[i] = a
b = pow(f[100000], m - 2, m)
fi[100000] = b
for i in range(99999, 0, -1):
	fi[i] = b * (i + 1) % m
	b = fi[i]
l = [[] for i in range(100001)]
p = [1] * 100001
for i in range(2, 100001):
	if p[i]:
		for j in range(i, 100001, i):
			p[j] = 0
			l[j].append(i)
for i in range(int(input())):
	(n, fr) = map(int, input().split())
	if fr == 1:
		if n == 1:
			print(1)
		else:
			print(0)
		continue
	ans = m + ncr(n - 1, fr - 1)
	c = 0
	l1 = []
	for i in range(2, len(l[n]) + 1):
		for j in combinations(l[n], i):
			x = 1
			for k in j:
				x *= k
			l1.append([i - 1, x])
	for j in l[n]:
		if n - j * fr >= 0:
			x = (n - j * fr) // j
			c += ncr(fr + x - 1, fr - 1)
			c %= m
	ans = (ans - c) % m + m
	l2 = [0] * 7
	for j in l1:
		if n - j[1] * fr >= 0:
			x = (n - j[1] * fr) // j[1]
			l2[j[0] + 1] += ncr(fr + x - 1, fr - 1)
			l2[j[0] + 1] %= m
	for i in range(2, 7):
		if i % 2 == 0:
			ans += l2[i]
			ans %= m
		else:
			ans += m
			ans -= l2[i]
			ans %= m
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
write = lambda x: sys.stdout.write(x + '\n')
debug = lambda x: sys.stderr.write(x + '\n')
writef = lambda x: print('{:.12f}'.format(x))
ans = []
M = 10 ** 9 + 7
N = 2 * 10 ** 5 + 10
g1 = [0] * (N + 1)
g2 = [0] * (N + 1)
inverse = [0] * (N + 1)
g1[0] = g1[1] = g2[0] = g2[1] = 1
(inverse[0], inverse[1]) = [0, 1]
for i in range(2, N + 1):
	g1[i] = g1[i - 1] * i % M
	inverse[i] = -inverse[M % i] * (M // i) % M
	g2[i] = g2[i - 1] * inverse[i] % M

def cmb(n, r, M=M):
	if r < 0 or r > n:
		return 0
	r = min(r, n - r)
	return g1[n] * g2[r] % M * g2[n - r] % M

def perm(n, r, M=M):
	if r < 0 or r > n:
		return 0
	return g1[n] * g2[n - r] % M

def hurui(n):
	pl = []
	mpf = [None] * (n + 1)
	for d in range(2, n + 1):
		if mpf[d] is None:
			mpf[d] = d
			pl.append(d)
		for p in pl:
			if p * d > n or p > mpf[d]:
				break
			mpf[p * d] = p
	return (pl, mpf)
from collections import defaultdict

def factor(num):
	d = defaultdict(int)
	if num == 1:
		d.update({1: 1})
		return d
	while num > 1:
		d[mpf[num]] += 1
		num //= mpf[num]
	return d
(pl, mpf) = hurui(100100)
q = int(input())
for i in range(q):
	(n, f) = list(map(int, input().split()))
	if f == 1:
		if n == 1:
			res = 1
		else:
			res = 0
	else:
		fs = factor(n)
		ks = list(fs.keys())
		vs = list(fs.values())
		res = 0
		for b in range(1 << len(ks)):
			v = 1
			s = 1
			for i in range(len(ks)):
				if b >> i & 1:
					v *= ks[i]
					s *= -1
			res += s * cmb(n // v - 1, f - 1) % M
			res %= M
	ans.append(res % M)
write('\n'.join(map(str, ans)))