如何在Python中反转%操作

sud*_*ang 2 python math modulo python-3.x

例如:

x = (y*6) % 26 #this is  a consistent formula
18 = (y*6) % 26
Run Code Online (Sandbox Code Playgroud)

我该如何解决y?或者有没有办法轻松反转 % 操作?

小智 5

你不能真正像这样反转模算术。模算术基本上返回等价组。想想日历...

日历(和时钟)是 mod 12。

10 月后 3 个月为一月,即 (10 + 3) % 12 == 1
10 月后 15 个月为一月。即 (10 + 15) % 12 == 1
等等...

所以你的问题似乎是在问你是否可以通过知道现在是哪个日历月来判断是哪一年,这当然是不可能的