% operator will return the remainder of the Integer division.
What modules actually does under the hood ?
Modules tend to remove cycles from the number, until it reaches a positive number that is smaller than the number of the cycle which we call modulo OR a negative number which we call a reminder.
However, Using % operator is time expensive.
To avoid using  % while getting the same result, we can use the following:
- While(a >= n) a -= n;(when- ais a positive number)
- While(a < 0) a += n;(when- ais a negative number)
 
- a = n*q + rthat means- r = a - n*qWhile- q is the integer division of a/nwhich means- a%n == a - n * Math.toIntExact(a/n)Which is sufficient when- ais a positive number.
 
- While ais a negative number, we can use(a%n + n) % nWhich will give you module.
Case Scenario on Clock:
if it is now 9 O'clock, what time after 4 hours => 9+4 = 13h => 13%12=1 while 12 is the cycle number in the clock
What if we need to calculate time before 24 hours (Yesterday) from now which is 9 O'clock, then:
24(2*12) => Yesterday Means 9-24 = -15h While the right answer is 9 , to solve this we will use (a%n + n) % n While a%n == (a - n * Math.toIntExact(a/n)) then -15 - 12 * Math.toIntExact(-15/12) = -3 => -3 + 12 = 9 => 9%12 => 9 - 12 * Math.toIntExact(9/12) = 9 Which is the right answer.
This is the code for the clock Scenario:
public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt(); // a = -15
    int n = scanner.nextInt(); // cycle = 12
    int reminder = a - (n * Math.toIntExact(a / n));
    int reminder_plus_n = (reminder + n);
    int modulo = reminder_plus_n - (n * Math.toIntExact(reminder_plus_n / n));
    System.out.println(modulo); // Answer = 9
}