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.
First line of input: T (Number of test cases)
In next T lines, each have one pair A B (0 < A, B <= 10^6)
One integer describing number of common divisors between two numbers.
Woo.. Fast input too takes 0.36 seconds.. O(sqrt(gcd(a, b)) using the std::__gcd available in C++.. Any hint on how to make it faster ??Last edit: 2016-01-11 17:06:33
std::__gcd(n,k) under <algorithm> ...can be used to get gcd without defining any function!
tle in c
atlast AC after several TLE
Very Tight Time limit. AC in c++ but TLE in python.
use euclidean algorithm to compute gcd :)
Abdulsalam Abdo Helal:
scanf and prinf is recommended to pass time
fast i/o and basic math !
If you are sure of your complexity. Change to Printf scanf, and make sure all your variables are declared as int not long long.
Nice problem.... :)