Use BigInteger
. int
or even unsigned long
is way too small to hold the product. And calculating integer values with double
is also problematic.
BigInteger
has a static method ModPow
made exactly for your purpose:
int N = 10379
int S1 = 3701;
int d = 37;
BigInteger T1 = BigInteger.ModPow(S1, d, N); // 7770
0
solved The modulus operator (%) doesn’t work for huge numbers