COMDIV - Number of common divisors

You will be given T (T<=10^6) pair of numbers. All you have to tell is the number of common divisors between 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 <= 10^6)

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
2014-03-29 10:16:11 [Lakshman]
Now on TOP.
2014-03-29 06:37:44 [Lakshman]
@Hassan Azzam You are getting TLE not because of scanf or printf it is your naive algo.the worst case complexity is O(sqrt(gcd(a,b))).

Last edit: 2014-03-29 06:38:00
2014-03-29 00:21:27 Hassan Azzam
problem needs to be burnt -_-
Despite using Scanf & int , i always get TLE.
2014-03-28 09:35:55 Bharath Reddy
cin and cout gives TLE.
scanf,printf --> AC
2014-01-23 13:17:53 siddhant gupta
do not use cin or cout. it wil give tle. wasted my 2 hrs on such a easy ques.


Last edit: 2014-01-23 13:18:05
2014-01-10 17:55:09 I am back
easy one AC in first attempt
2014-01-04 20:53:54 Vipul Pandey
Got AC in 1st attempt! Easy one! took only 15 minutes.
2013-12-25 05:16:11 Archangel
i am getting WA pls help someone
<snip>

Last edit: 2023-02-01 12:23:41
2013-10-17 17:53:24 Himanshu
simple mathematics
2013-09-20 17:57:37 P_Quantum
AC with O(sqrt(gcd(a,b))).. !!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.