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
2013-09-20 17:57:37 P_Quantum
AC with O(sqrt(gcd(a,b))).. !!
2013-09-17 09:18:47 Mahesh Mishra
dont use long long and cin cout .. it will time out
2013-08-10 12:54:45 Prakhar Gupta
Is 0,0 also a test case....i m gettin WA while it run perfectly on ideone....my id 9812939

p.s. accepted

Last edit: 2013-09-16 08:50:46
2013-07-24 13:09:51 Nishant Gupta
complexity O(sqrt(gcd(a,b))
2013-07-23 15:29:46 flipster
cake walk:)
2013-07-20 09:18:17 Pranye Mawai
enjoyd doin it ... :D
2013-07-13 19:48:56 tamed
@ps my id 9651682 why i m not getting output and why i m also getin wrong answer
2013-06-17 19:17:43 Hasil Sharma
I don't know why I am getting WA while using C , I have used correct logic int type for all the digits and double for storing sqrt of gcd :/
W.A Finally :)

Last edit: 2013-06-30 20:44:39
2013-05-25 17:50:02 Anick Saha
long long to int , cinto scanf ... then it gets AC :-/
2013-05-16 19:01:43 Shubham Sharma
SIGSEGV in my code ..
Submission id : 9278917 plz help
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.