Overflow: a*a mod n
<p>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 either. This is in C++ and I'm using int 64's.</p>

<p>edit: example a value = 821037907258, which overflows if you square it</p>

<p>I am using DevCPP and I've already tried getting big-integer libraries working to no avail.</p>

<p>edit 2: No, there's no pattern to these numbers.</p>
