问题
I'm stuck on this cryptography problem using multiplication of a whole number and a fraction mod 10.
Here is the equation:
7 * (4/11) mod 10 =?
I know I am supposed to convert this to an integer since the mod operator does not work with fractions, but I cannot figure this one out. Obviously,
7 * (4/11) = 28/11,
but I cannot get the mod 10 of a fraction. The instructor wants the exact answer, not a decimal. Any help would be greatly appreciated!
回答1:
8
8 is the correct answer indeed.
7*4/11 mod 10
means we're looking at 7*4*x mod 10
where x is the modular inverse of 11 modulo 10, which means that 11*x mod 10 = 1
.
This is true for x=1
(11*1 mod 10 = 1
)
So 7*4*x mod 10
becomes 7*4*1 mod 10
which is 28 mod 10 = 8
回答2:
Have a look here: "Is it possible to do modulo of a fraction" on math.stackexchange.com.
One natural way to define the modular function is
a (mod b) = a − b ⌊a / b⌋
where ⌊⋅⌋ denotes the floor function. This is the approach used in the influential book Concrete Mathematics by Graham, Knuth, Patashnik.
This will give you 1/2(mod3)=1/2.
To work through your problem, you have a = 7 * (4/11) = 28/11
, and b = 10
.
a / b
= (28/11)/10 = 0.25454545...
⌊a/b⌋
= 0
b ⌊a/b⌋
= 0 * 0 = 0
a - b ⌊a/b⌋
= 28/11 - 0 = 28/11
This means your answer is 28/11.
Wolfram Alpha agrees with me and gives 28/11
as the exact result. Google also agrees, but gives it as a decimal, 2.54545454.....
A fraction is an exact answer and not a decimal.
回答3:
I can speculate that the notation is wrong, and that the whole expression is supposed to be evaluated in mod 10 at each intermediate stage. Since ( 11 mod 1 ) is 1, then answer is (7 * 4) mod 10 = 8.
Imagine a calculator with support only for the ones digit.
I'm not saying this is the right answer, I agree 28/11 is the right answer as given, but I am trying to get into the head of the professor. This is common in cryptography, where every calculation is performed mod 2 ^ 256 or so.
回答4:
This is how the original question probably should have been written, as this has a different meaning. When the (mod 10) is written at the end, it means that each term is evaluated with an implied mod 10
operation.
The problem is a bit weird, as the modulo value of 10 is not general purpose, because it is not prime. For example, the following can not be evaluated because 1/2 mod 10
is not defined, because 2 and 10 are not coprime.
回答5:
So, here is the correct answer from the instructor. I have no idea how he came up with this:
7 4/11 mod 10 = ((7 4) mod 10)(11−1 mod 10) mod 10
= (28 mod 10)(1 mod 10) mod 10
= (8)(1) mod 10
= 8 mod 10
回答6:
Using Python:
from fractions import Fraction
from math import fmod
print (fmod(Fraction(28, 11), 10))
The result will be 2.545454545454. So I guess 8 is wrong.
来源:https://stackoverflow.com/questions/32418693/modular-arithmetic-using-fractions