Link to home
Start Free TrialLog in
Avatar of Mickeys
MickeysFlag for Sweden

asked on

Evenly divisible

Read question. Is my answer correct? User generated image

(123^121+121^123) mod 122= ((122+1)^121) mod 122+ ((122-1)^123)mod 122= (1^121) mod 122 +((-1)^123) mod 122 = 1 mod 122+ (-1) mod 122= (1-1) mod 122 =0
Avatar of phoffric
phoffric

Where % ~ mod, it looks like you are using these principles:
aa % n = (a % n) (a % n)
a^k % n = (a%n)^k
(a+b) % n = a%n + b%n
More generally, you could write:
(n+1)^(n-1)  % n = [ (n+1) % n ] ^ (n-1) = [ n % n +1 % n ] ^ (n-1) = [ 0 + 1 ] ^ (n-1) = 1
(n-1)^(n+1)  % n = [ (n-1) % n ] ^ (n+1) = [ n % n - 1 % n ] ^ (n+1) = [ 0 - 1 ] ^ (n+1) = -1
Avatar of Mickeys

ASKER

So to get the correct answer. Would I use this
(123^121+121^123) mod 122= ((122+1)^121) mod 122+ ((122-1)^123)mod 122= (1^121) mod 122 +((-1)^123) mod 122 = 1 mod 122+ (-1) mod 122= (1-1) mod 122 =0

or this?
(n+1)^(n-1)  % n = [ (n+1) % n ] ^ (n-1) = [ n % n +1 % n ] ^ (n-1) = [ 0 + 1 ] ^ (n-1) = 1
(n-1)^(n+1)  % n = [ (n-1) % n ] ^ (n+1) = [ n % n - 1 % n ] ^ (n+1) = [ 0 - 1 ] ^ (n+1) = -1

I prefer symbols, but you can choose the approach you feel more comfortable with.

Let n = 122, then
(n+1)^(n-1)  % n = (122+1)^(122-1)  % 122 = (123^121) mod 122

and
(n-1)^(n+1)  % n = (122-1)^(122+1)  % 122 = (121^123) mod 122

Can you make the final conclusions from this substitution by comparing it with your OP?
Avatar of Mickeys

ASKER

no :-(
>> no :-(
Could you elaborate?
For example, what part of the substitution are you having trouble with?
Avatar of Mickeys

ASKER

well all I really wanted to know was if my solution was correct
SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
These are your steps with the justifications. Looks complete to me.
Oh, that first step also used (a+b) % n = a%n + b%n