Re: Enigma 1494 - Powerful logic



On 3 Jul, 09:40, Simon Tatham <ana...@xxxxxxxxx> wrote:
Richard Heathfield  <r...@xxxxxxxxxxxxxxx> wrote:

...> As Gareth mentioned in passing in his answer, the theorem you're
looking for is the Euler-Fermat theorem (or Fermat-Euler theorem),
which states that if a and c are coprime then a^phi(a) is congruent
to 1 mod c, where phi is
 http://en.wikipedia.org/wiki/Euler's_totient_function
Hence, if you're trying to raise a to some arbitrary power b mod c,
you can't get away with reducing b itself mod c, but you can reduce
b mod phi(c).

For coprime a,b, phi(ab)=phi(a)phi(b); and for any prime power,
phi(p^a) = (p-1)p^(a-1). Hence, phi(1000) = phi(2^3)*phi(5^3) =
1*2^2*4*5^2 = 400 (as Gareth also mentioned). So if your eventual
result will be reduced mod 1000, you can reduce b mod 400. (And you
are of course correct in saying you can also reduce a mod 1000.)
--
Simon Tatham         "Imagine what the world would be like if
<ana...@xxxxxxxxx>    there were no hypothetical situations..."

I think the rationale for this puzzle was to expose those who like
numbers to the
howler: mod(a^b, n) = mod(a ^ (mod(b,n)), n) -- which it isnt

since no-one followed up with the calculation, let me.
123456 = 256 mod 400
and 256 is 2^8 and this is significant, since to calculate exponents
to a modulus you need to square and multiply in a russian style
but here all we need to do is square 3, 8 times, each mod 1000.

after 81 the "1" is invariant, and if you have at one stage three
digits
(a, b, 1) then the next stage gives (b^2 + 2a, 2b, 1) (with carry as
required)
so the second digit is a power of 2 mod 10 and we can write down 21
for the 8th stage right away
the third digit just needs to be calculated - cant see an easy way and
yes it is 5.

interestingly the first solution noted that 3^100 = 3 mod 1000 so the
answer is also 3^56
this looks easier to do, but 56 = 111000 binary and so we need to
SMSMSSS (S = square, M=multiply by 3) which is 7 operations rather
than 8, so it isnt that much easier.
HTH
JJ
.



Relevant Pages

  • Re: Rabin vs. RSA/ElGamal
    ... Do you mean that people use the "square and multiply" approach/idea ... When considering the "next" digit of the exponent, ... the power of 16 and then multiply times the plaintext to the power of ... use the binary form of square and multiply to compute the plaintext ...
    (sci.crypt)
  • Re: Calculating Power
    ... it's customary to represent voltage with the root mean ... That is because rms * rms = ms, the mean square. ... Since power is the ... In your current calculation, you have calculated the dissipation due ...
    (rec.audio.tubes)
  • final solutions on second decimal (a*L + b) where sqrt2 = 1d414....(2L + 0)
    ... has some truth value. ... And that Incompleteness extends not only to ... have a closure to number digit arrangements. ... I need a square root operation to be complete on them. ...
    (sci.math)
  • which is going to win? Godel or AP-Reals, sqrt2 = 1d414....(2L + 0)
    ... has some truth value. ... And that Incompleteness extends not only to ... have a closure to number digit arrangements. ... I need a square root operation to be complete on them. ...
    (sci.math)
  • Re: Questions on interfacing to current sense transformer
    ... measurements over the internet. ... get all phase angles every pass. ... The corrected mean square is the mean square minus the square of the ... The result is true power. ...
    (sci.electronics.design)