There is a formula:

RESULT = (CONST + var) % MOD 

RESULT is an integer,> = 0

CONST , var , MOD - integers,> 0

Question:

How var will change if:

  • MOD increase by 1
  • MOD decrease by 1

However, RESULT and CONST should not change.

Not brute force.

Closed due to the fact that the essence of the question is not clear by the participants aleksandr barakin , HamSter , pavel , Denis , ermak0ff 11 Nov '16 at 7:03 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • If mod> 0 and = 1 by condition, then mod-1 = 0, then there will be no solution. This is me, by the way) This, by the way, may be one of the solutions - daydark
  • but surely there are no more restrictions? - Grundy

1 answer 1

Found a solution. Original equation

 RESULT = (CONST + var) % MOD 

Let NEWMOD be an enlarged or reduced MOD .

 var = NEWMOD - (CONST - RESULT) % NEWMOD 

On examples.

On the original example.

 (25 + 15) % 16 = 8 
  • CONST = 25
  • var = 15
  • MOD = 16
  • RESULT = 8

Increase:

 NEWMOD = MOD + 1 = 17 var = 17 - (25 - 8) % 17 = 17 - 0 = 17 (25 + 17) % 17 = 8 

Decrease:

 NEWMOD = MOD - 1 = 15 var = 15 - (25 - 8) % 15 = 15 - 2 = 13 (25 + 13) % 15 = 8 

UPD: As for the proof.

Transfer the result to another part of the equation or, more simply, reduce both parts by the value of the result.

Because on the right side, we do not have division, but the remainder of it, then it is permissible.

 CONST + var >= RESULT 

because RESULT is the remainder of the division

 (25 - 8 + var) % 16 = 0 => (17 + var) % 16 = 0 

In other words (special case):

 17 + var = 16 => var = 16 - 17 = -1 (25 + (-1)) % 16 = 8 

I must say that the answer here is not one. The answer will be numbers with an interval in the value of the module.

In this case: -1, 15, 31, 47, etc.

  • And the proof? - cronfy
  • @cronfy (N-(CR)%N+C)%N = 0 - C+R+C = R - Harry
  • evidence added in response - Vitaly