Not sure what the advantage of Python is in this case. Your code is basically the same, except that it doesn't have any dollar signs or semicolons. I never liked Python's "x if cond else y" as a replacement for "cond ? x : y", it just doesn't seem right to put the condition in the middle of the expression. But I have to admit that Python's built-in multiple precision ints are a huge advantage for certain kinds of math programming.