Problem: Nimbus, the techical festival of NIT Hanirpur is coming and thus Arun, the core-cordinator of departmental team of CSE, decided a conduct a game. In this game, the participant will be given a natural number N and will be asked T questions of form Type K.

Here Type denotes the type of question asked and K denotes a natural number.

If Type=1, the participant must find the number of natural numbers which is divisor of both N and K.

If Type=2, the participant must find the number of natural numbers which is divisor of N and is divisible by K.

If Type=3, the participant must find the number of natural numbers which is divisor of N and is not divisible by K.

As it will be very difficult for Arun to tell manually whether the asnwer given by participant is correct or not. So, he decided so write a code for it. As Arun is very busy for NIMBUS preparations, he has given this task to you.

INPUT

The first line of input contains 2 integers N and T, denoting the natural number and the number of questions asked respectively.
The next T lines contains 2 integers Type and K, denoting the Type of question asked and the natural number respectively.

OUTPUT

For each test case output a single integer (one per line), that is the answer to the question.

CONSTRAINTS

1 ≤ N ≤ 10^12

1 ≤ T ≤ 5*10^5

1 ≤ Type ≤ 3

1 ≤ K ≤ 10^12

SAMPLE INPUT
12 6
1 6
1 14
2 4
2 3
3 12
3 14

SAMPLE OUTPUT
4
2
2
3
5
6

Explanation

Divisors for each question asked:

{1,2,3,6}

{1,2}

{4,12}

{3,6,12}

{1,2,3,4,6}

{1,2,3,4,6,12}

Solution (in PYTHON):

Solution:
from sys import stdin
di = {}
n,t = map(int,stdin.readline().split())
div = []
i = 1
def gcd(a,b):
	while a%b:
		x = a%b; a=b; b=x
	return b
def solve(n):
	if n==1:
		return 1
	if di.get(n,0):
		return di[n]
	
while i*i<=n:
	if n%i==0:
		div.append(i)
		if i*i!=n:
			div.append(n/i)
	i+=1
div.sort()
#print div
l = len(div)
for i in xrange(l):
	cur = 0
	for j in xrange(i+1):
		if div[i]%div[j]==0:
			cur+=1
	di[div[i]] = cur
#print di
'''
If Type=1, the participant must find the number of natural numbers which is divisor of both N and K.
If Type=2, the participant must find the number of natural numbers which is divisor of N and is divisible by K.
If Type=3, the participant must find the number of natural numbers which is divisor of N and is not divisible by K.
'''
for _ in xrange(t):
	ty,k = map(int,stdin.readline().split())
	if ty==1:
		g = gcd(k,n)
		print di[g]
	elif ty==2:
		if n%k:
			print 0
		else:
			print di[n/k]
	else:
		co = 0
		for i in div:
			if i%k:
				co+=1
		print co