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.
AC in 1 go :)
Man , Never thought i would end up with fastest submission till date ( 0.10s )
use sieve first then gcd
If TLE: use || ios::sync_with_stdio(0); cin.tie(0); || in C++ to make I/O fast.
use scanf and printf to resolve TLE error along with better mathematical logic
cout, cin gave me few TLE and then god knows what gave me WA - finally correct !
Using cin,cout along with fast ip/op passed in every problem I have solved so far,so never used scanf,printf in a C++ code, but here I don't know why using scanf,printf becomes a compulsion.This thing annoys me a lot.If anyone can help,pls help me know that what's the use of "ios_base::sync_with_stdio(false); cin.tie(NULL) in a c++ code" if we always have to use scanf,printfLast edit: 2017-03-21 16:19:59
AC in 1 go with c++ cin,cout working fine in 0.35 sec
Lovely concept! Initially I was brute-forcing but the comments were really helpful!