求大数平方的模 [英] Finding modulo of large numbers squared

查看:139
本文介绍了求大数平方的模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在编写一个程序,该程序需要计算:

I am currently writing a program that requires the calculation of:

(x ^ 2)mod y

(x^2) mod y

这两个数字都是整数.两者都可以是很大的数字,尽管它们都不会超过10 ^ 9.

Both these numbers are integers. Both can be large numbers, though they never exceed 10^9.

这仍然足以使x平方溢出整数.速度对于此代码至关重要,因此不能使用逐步乘法.

That is still enough to overflow integer for x squared. Speed is crucial for this code so gradual multiplication is not usable.

谢谢.

推荐答案

解决方案非常简单.我用Long代替了int,并且有效.

The solution was really simple. I used Long, instead of int and it works.

这篇关于求大数平方的模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆