Play with Queries

4.2

9 votes
Problem

Ankur loves number theory very much. Now it is time to solve a new kind of problem.

There is given a natural number N. Ankur has to answer Q queries of the form T K.

Here T is the type of query and K is the natural number.

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

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

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

Ankur can solve all these queries, but you will be hungry for night if this happens, because Ankur will not have free time to cook a meal. Therefore you compromise with him and decided that everyone must do his/her own job. You must program and Ankur must cook.

INPUT

  • There will be 2 numbers in the first line: N and Q.
  • Q lines follow with 2 numbers each: T and K.

OUTPUT

For each of the Q lines you must output the result for corresponding query in separate line.

CONSTRAINTS

1<=N<=10^12

1<=Q<=5*10^5

1<=T<=3

1<=K<=10^12

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Numbers for each query:

{1,2,3,6}

{1,2}

{4,12}

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

Editor Image

?