Collatz Conjecture Meet of 2 Numbers
Integer Overflow

I suspect that your problem has to do with integer overflow and not with your algorithm itself.  If you don't guard against integer overflow, doing A = A * 3 + 1 could result in a negative value, and you may end up in an infinite loop where you never reach 1.  Try changing your variables to long and resubmit.

By the way, to test for infinite loop cases, try the starting value 113383.

Other suggestions


You could use a HashMap instead of a TreeMap.  A HashMap has \$O(1)\$ insert and lookup compared to \$O(\log n)\$ for a TreeMap.  The difference for this program will be very small though.
In the A loop, you shouldn't have to check if visited.containsKey(A) because the collatz sequence never repeats until you reach 1.  You can just always add A to the map.
If b is 1, your program never prints anything.