You've got a bit of a mix of unsigned and signed numbers in your code - you should try to avoid this when possible. Also you're attempting to use %llu
on a signed long long - you should use %lld
in this case.
But there is a more subtle problem in play here. In this line:
long long encrypt =(long long)pow((double) num,3) % 33;
pow
returns a double
, which won't guarantee all the precision you're looking for. You're going to end up losing a few digits when you cast to long long
. Unfortunately C doesn't provide a good alternative for computing exponentials, so you'll need to implement something yourself or use a library (some of the other answers have suggested some).
If you want to implement one yourself, a great article on fast exponentiation by squaring can be found on Wikipedia here: Exponentiation by squaring
They provide some pseudo-code that should be obvious for coding in C.
But lastly, in general your code is going to be limited by the size of long long
, or whatever type you choose. Ultimately for large numbers you should use some other library, or find a better algorithm. In this case, you're computing a power and then taking a modulus - which is exactly what Modular Exponentation algorithms can accomplish without having to deal with these libraries. You can find a Wikipedia article here: Modular Exponentiation