# Modular Equivalence

Given two numbers $$\x,y > 2, x≠y \$$ output all integers $$\m\$$ such that $$x + y \equiv x \cdot y \pmod m$$ $$x \cdot y > m > 2$$

Two integers

## Output

A list of integers

## Test cases

3, 4 -> 5
5, 8 -> 3, 9, 27
29, 9 -> 223
26, 4 -> 37, 74
13, 11 -> 7, 17, 119
6258, 571 -> 463, 7703, 3566489

• Must we be able to accept input in any order or can we require a specific order? Commented Feb 4 at 20:20
• @Shaggy you have to specify how you take input but other than that, its up to you Commented Feb 4 at 20:33

# 05AB1E, 8 7 bytes

<P<Ñʒ2›


-1 thanks to Kevin Cruijssen

Lists the divisors of $$\xy-x-y\$$ greater than $$\2\$$.

• If you take the input as a pair, the *α¹- can be <P< for -1 byte. (And the ʒ2› has some equal-bytes alternatives, like ¦2K, 2LK or ć·K, but I haven't found anything shorter.) Commented Feb 2 at 13:32

# MathGolf, 8 bytes

(ε*(─2╒-


Try it online.

Explanation:

(        # Decrease both values in the (implicit) input-pair: [x-1,y-1]
ε*      # Multiply them together: (x-1)*(y-1)
(     # Decrease that by 1 as well: (x-1)*(y-1)-1
─    # Get all divisors
2╒  # Push [1,2]
- # Remove those values from the divisors-list
# (after which the entire stack is output implicitly as result)


# Thunno 2, 7 bytes

×__Fæ2>


Attempt This Online!

Based on Command Master’s idea, implemented a bit differently

×        # Multiply.          X * Y
_       # Swapped subtract.  X * Y - X
_      # Swapped subtract.  X * Y - X - Y
F     # Factors.
æ    # Filter by:
2>  #   Greater than 2?


I chose Thunno 2 because of that swapped subtraction operator. It's the only stack golflang which has swapped versions of arithmetic operations, as far as I know.

# Raku (Perl 6) (rakudo), 41 bytes

{[3..($^x*$^y)].grep: 0==($x+$y-$x*$y)%*}


Attempt This Online!

# Python, 52 bytes

lambda x,y:[i for i in range(3,x*y)if(x+y)%i==x*y%i]


Attempt This Online!

# Go, 80 bytes

func(x,y int)(M[]int){for m:=3;m<x*y;m++{if(x*y-x-y)%m<1{M=append(M,m)}}
return}


Attempt This Online!

Uses the factors of $$\xy-x-y \gt 2\$$ method.

# Go, 81 bytes

func(x,y int)(M[]int){for m:=3;m<x*y;m++{if(x+y)%m==x*y%m{M=append(M,m)}}
return}


Attempt This Online!

Formula as verbatim, $$\xy \equiv x+y \pmod m\$$.

# Nekomata, 8 bytes

ᵋ*+-Ď~2>


Attempt This Online!

ᵋ*+-Ď~2>
ᵋ*          x * y
+         x + y
-        minus
Ď       divisors
~      choose an element from the list
2>    check if it is greater than 2


# APL (Dyalog APL), 22 17 16 bytes

-5 bytes thanks to @ovs
-1 bytes thanks to @att

(2↓2∪∘⍸0=⍳|⊢)×-+


Attempt This Online!

(2↓2∪∘⍸0=⍳|⊢)×-+­⁡​‎‎⁪⁡⁪⁠⁪⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁡⁪‏‏​⁡⁠⁡‌⁢​‎⁪⁪⁠⁪⁪⁠‎⁪⁡⁪⁠⁪⁣⁤⁪‏‏​⁡⁠⁡‌⁣​‎‎⁪⁡⁪⁠⁪⁣⁣⁪‏‏​⁡⁠⁡‌⁤​‎‎⁪⁡⁪⁠⁪⁣⁢⁪‏‏​⁡⁠⁡‌⁢⁡​‎‎⁪⁡⁪⁠⁪⁢⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁡⁪‏‏​⁡⁠⁡‌⁢⁢​‎‎⁪⁡⁪⁠⁪⁢⁣⁪‏‏​⁡⁠⁡‌⁢⁣​‎‎⁪⁡⁪⁠⁪⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁪‏‏​⁡⁠⁡‌⁢⁤​‎‎⁪⁡⁪⁠⁪⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁪‏‏​⁡⁠⁡‌⁣⁡​‎‎⁪⁡⁪⁠⁪⁤⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁤⁪‏‏​⁡⁠⁡‌­
(2↓2∪∘⍸0=⍳|⊢)     ⍝ ‎⁡monadic function to get factors greater than 2:
⊢      ⍝ ‎⁢  arg
|       ⍝ ‎⁣      mod
⍳        ⍝ ‎⁤          each number in range [1;arg]
0=         ⍝ ‎⁢⁡  boolean vector, marking where result is 0
⍸           ⍝ ‎⁢⁢  ‎⁢⁢get indices of 1s
2∪             ⍝ ‎⁢⁣  prepend 2 if not in array
2↓               ⍝ ‎⁢⁤  drop first two elements (i.e. 1 and 2)
×-+  ⍝ ‎⁣⁡pass (⍺ × ⍵) - (⍺ + ⍵) to the function
💎


Created with the help of Luminespire.

# C (gcc), 56 bytes

i;f(x,y){for(i=x*y;--i>2;)(x*y-x-y)%i?:printf("%d ",i);}


Try it online!

=let(p,A1*B1,s,sequence(1,p,3),filter(s,0=mod(p-A1-B1,s)))


Put $$\x\$$ in cell A1, $$\y\$$ in cell B1 and the formula in cell C1.

-3 bytes thanks to AZTECCO.

x#y=[m|m<-[3..x*y],1>mod(x*y-x-y)m]


Try it online!

# Charcoal, 19 bytes

Ｆ²⊞υＮＩΦ…³Πυ¬﹪⁻ΠυΣυι


Try it online! Link is to verbose version of code. Explanation:

Ｆ²⊞υＮ


Input x and y and push them to the predefined empty list.

ＩΦ…³Πυ¬﹪⁻ΠυΣυι


Output all numbers between 3 and the product of the list that are factors of the difference between the product and the sum.

21 bytes for a faster version that can handle the last test case in a more reasonable amount of time:

Ｆ²⊞υＮＩ⁺³⌕Ａ﹪⁻ΠυΣυ…³Πυ⁰


Try it online! Link is to verbose version of code. Explanation: Vectorises the remainder check and then finds the positions of the zero remainders.

# R, 32 bytes

\(x,y,a=x*y-x-y)which(!a%%3:a)+2


Attempt This Online!

Port of Command Master's 05AB1E answer.

# R, 35 bytes

\(x,y,M=3:(p=x*y))M[p%%M==(x+y)%%M]


Attempt This Online!

Straightforward approach.

# UiuaSBCS, 19 15 bytes

▽=⊃∩◿∘,:↘3⇡.⊃×+


Try it!

-4 bytes thanks to Tbw

• 15 bytes uiua.org/…
– Tbw
Commented Feb 2 at 21:07
• @Tbw Nice, thanks! Commented Feb 2 at 21:11

# Wolfram Language (Mathematica), 29 bytes

Divisors[##-##]/. 1|2->Set@$&  Try it online! Input [x, y]. ##-## is not zero - it computes the sum minus the product of arguments. # JavaScript (V8), 46 bytes x=>y=>{for(m=x*y,q=m-x-y;--m>2;)q%m||print(m)}  Try it online! # JavaScript (ES6), 52 bytes (x,m=2)=>g=y=>++m<x*y?((x*y-x-y)%m?"":m+" ")+g(y):""  Try it online! # TI-BASIC, 25 bytes For(M,3,prod(Ans)-1 If not(fPart(M⁻¹min(ΔList(Ans Disp M End  Takes input in Ans as a list of two integers. Add a ) to the end of the first line to make it faster. # Jelly, 8 bytes ’P’ÆD>Ƈ2  Try it online! Port of Command Master’s 05AB1E answer. -1 byte and a bugfix thanks to @Bubbler ## Explanation: ’P’ÆD>Ƈ2­⁡​‎‎⁪⁡⁪⁠⁪⁡⁪‏‏​⁡⁠⁡‌⁢​‎‎⁪⁡⁪⁠⁪⁢⁪‏‏​⁡⁠⁡‌⁣​‎‎⁪⁡⁪⁠⁪⁣⁪‏‏​⁡⁠⁡‌⁤​‎‎⁪⁡⁪⁠⁪⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁪‏‏​⁡⁠⁡‌⁢⁡​‎‎⁪⁡⁪⁠⁪⁢⁣⁪‏‏​⁡⁠⁡‌⁢⁢​‎‎⁪⁡⁪⁠⁪⁢⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁤⁪‏‏​⁡⁠⁡‌­ ’ # ‎⁡Decrement both values in the list: [x - 1, y - 1] P # ‎⁢Product of the list: (x - 1) * (y - 1) ’ # ‎⁣Decrement again: ((x - 1) * (y - 1)) - 1 ÆD # ‎⁤Get the divisors Ƈ # ‎⁢⁡Keep items that satisfy the condition below > 2 # ‎⁢⁢Greater than 2 💎  Created with the help of Luminespire. • ÆḌ should be ÆD I think? Also >2$Ƈ­⁡​‎‎ can be >Ƈ2­⁡​‎‎. Commented Feb 4 at 23:51
• @Bubbler fixed. Commented Feb 5 at 18:58

# Retina 0.8.2, 50 bytes

.+
$* 1(?=1+¶1(1+))$1
M!&(111+)\b(?<=^11\1+)
%1


Try it online! Link is to test suite for faster test cases that splits input on non-digits and spaces the outputs apart. Explanation:

.+
$*  Convert to unary. 1(?=1+¶1(1+))$1


Calculate 1+(x-1)(y-1), as that's golfier than trying to subtract x or y afterwards.

M!&(111+)\b(?<=^11\1+)


Subtract 2 and find all factors that are greater than 2.

%1


Convert to decimal.

# PowerShell Core, 45 bytes

param($a,$b)3..($p=$a*$b)|?{!(($a+$b-$p)%\$_)}


Try it online!

Saved two bytes using rajashekar's method, upvote their answer!