Doubt in modular exponentation

Firstly, Formatting.

Secondly, That’s because y is small. Use y=10^7 . Also pow(x,y,m) uses modular exponentiation. You don’t need to write it yourself.