in reply to math problems

Are your numbers over 2 billion? %d uses a signed native integer, usually 32 bit of 64 bit in size. Use %.0f instead.
$ perl -E'printf "%d\n", 2**34' -1 $ perl -E'printf "%.0f\n", 2**34' 17179869184