I need to calculate a*a
mod n
but a
is fairly large, resulting in overflow when I square it. Doing ((a % n)*(a % n)) % n
doesn't work because (n-1)2 can overflow. This is in C++ and I'm using int64_t
Edit:
Example value: a = 821037907258 and n = 800000000000, which overflows if you square it.
I am using DevCPP and I've already tried getting big-integer libraries working to no avail.
Edit 2:
No, there's no pattern to these numbers.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…