COMDIV - Number of common divisors

You will be given T (T ≤ 106) pairs of numbers. All you have to tell is the number of common divisors between the two numbers in each pair.

Input

First line of input: T (Number of test cases)
In next T lines, each have one pair A B (0 < A, B ≤ 106)

Output

One integer describing number of common divisors between two numbers.

Example

Input:
3
100000 100000
12 24
747794 238336 Output: 36
6
2

Added by:Mir Wasi Ahmed
Date:2010-10-31
Time limit:0.600s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own problem, used in UODA TST

hide comments
2015-09-15 14:30:30 Abdulsalam Abdo Helal
scanf and prinf is recommended to pass time
2015-09-10 10:00:03 Abishek
fast i/o and basic math !
2015-08-20 16:03:11 Medo
If you are sure of your complexity. Change to Printf scanf, and make sure all your variables are declared as int not long long.
2015-08-18 15:56:38
Nice problem.... :)
2015-08-15 16:04:40
AC in first go.....Basic Math nothing else!
2015-08-08 11:16:29 Indian Cyber Army (IndiShell)
My code is running perfectly on Dev C++ but here its showing runtime error with floating point exception. I have used long long int. can you please point out the error to me.
<snip>

Last edit: 2023-02-01 12:22:55
2015-06-25 11:55:55 Sue
AC in the first go ~
use printf scanf ~
2015-06-15 12:58:44 Varun Gambhir
All those getting TLE with sqrt(n) approach and using C/C++, use scanf printf instead of cin and cout.
2015-05-15 22:31:40 excursionist
Loved it !!
AC in first go..!! xD

Last edit: 2015-06-24 06:08:26
2015-03-10 06:15:02 [Lakshman]
@Muhammad Annaqeeb: When pyramid cluster was functional the time limit was 6s now the problem has been moved to CUBE cluster, time limit is reduced to 0.6s. As CUBE is 20x times faster than Pyramid. So O(sqrt(gcd(a,b))) can easily pass, it is also recommended to use scanf & printf.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.