My prof does not like the use of modulo since it's not efficient enough, but I'm not sure how else I can get the same answer using a logic operator or something. Can someone help me out with how I can do this?
j = (j + 1) % a.length;
If you square both sides of each equation then you can omit the modulus signs (as (x+3)^2 and (1-x)^2 will both be positive, regardless of whether x is a positive or negative number.)
. The rule says to multiply the input by 3 and then add 1. Intuitively, the rule for the inverse should just reverse this process: subtract 1, then divide by 3. In fact, mod 7 we can divide by 3 by just multiplying by 3's multiplicative inverse (which is 5), so this rule makes sense modulo 7 as well.
This should do the trick.
int k = a.length;
int d = (j+1)/k;
j = (j+1) - d*k
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With