Inverting modulas???

In equaltion,

x%3=2

how can i calculate x??
How many x do you want?
2 % 3 = 2
5 % 3 = 2
etc etc

DEXNOOBCODER (1)
In equaltion,

x%3=2

how can i calculate x??


x = anything*3+2

try it?
5*3 is 15, +2 is 17.
17%3 = ?

11*3 = 33, +2 = 35.
35%3 = ?

so its not any one X. its a great many values... {2,5,8, ... +3 forever}
Last edited on
x%3 == 2

x == 3n + 2 for any integer n
Caution, mes amis!

1
2
3
4
5
#include <iostream>
int main()
{
   for ( int n = -5; n <= 5; n++ ) std::cout << ( 3 * n + 2 ) % 3 << '\n';
}
Not our fault the percent sign operator doesn't do proper modular arithmetic!
1
2
3
int modulo(int x, int N){
    return (x % N + N) % N; // https://stackoverflow.com/a/42131603
}
Last edited on
I think its a "remainder operator" not a "modulo operator". Restrict to non-negative n in this problem.
Last edited on
Topic archived. No new replies allowed.