fork download
  1. from fractions import gcd
  2.  
  3. mod = 1000000007
  4. t = int(raw_input())
  5. while t:
  6. a,b = map(int,raw_input().split())
  7. if ( gcd(a,b)==1 ):
  8. print (a*b - a - b)%mod
  9. else:
  10. print 'infinite solutions'
  11.  
  12. t-=1
Success #stdin #stdout 0.02s 8656KB
stdin
2
3 4
5 7
stdout
5
23