Skip to main content
Commonmark migration
Source Link

#05AB1E, 11 10 9 7 bytes

05AB1E, 11 10 9 7 bytes

L+.Δ‚ÕË 

-1 byte with help from @ExpiredData.
-2 bytes thanks to @Grimmy.

Outputs -1 if no \$m\$ exists.

Try it online or verify all test cases.

Explanation:

L # Push a list in the range [1, (implicit) input-integer n] + # Add the (implicit) input-integer n to each to make the range [n+1, 2n] .Δ # Get the first value of this list which is truthy for # (or results in -1 if none are truthy): ‚ # Pair the current value with the (implicit) input-integer n Õ # Get the Euler's totient of both Ë # Check whether both are equal to each other # (after which the result is output implicitly) 

Most answers use \$n^2\$ as the range to check in, but this answer uses \$2n\$ instead to save a byte. If we look at the Mathematica implementation on the oeis sequence A066659 we can see it also uses the range \$[n+1, 2n+1)\$ to check in.

#05AB1E, 11 10 9 7 bytes

L+.Δ‚ÕË 

-1 byte with help from @ExpiredData.
-2 bytes thanks to @Grimmy.

Outputs -1 if no \$m\$ exists.

Try it online or verify all test cases.

Explanation:

L # Push a list in the range [1, (implicit) input-integer n] + # Add the (implicit) input-integer n to each to make the range [n+1, 2n] .Δ # Get the first value of this list which is truthy for # (or results in -1 if none are truthy): ‚ # Pair the current value with the (implicit) input-integer n Õ # Get the Euler's totient of both Ë # Check whether both are equal to each other # (after which the result is output implicitly) 

Most answers use \$n^2\$ as the range to check in, but this answer uses \$2n\$ instead to save a byte. If we look at the Mathematica implementation on the oeis sequence A066659 we can see it also uses the range \$[n+1, 2n+1)\$ to check in.

05AB1E, 11 10 9 7 bytes

L+.Δ‚ÕË 

-1 byte with help from @ExpiredData.
-2 bytes thanks to @Grimmy.

Outputs -1 if no \$m\$ exists.

Try it online or verify all test cases.

Explanation:

L # Push a list in the range [1, (implicit) input-integer n] + # Add the (implicit) input-integer n to each to make the range [n+1, 2n] .Δ # Get the first value of this list which is truthy for # (or results in -1 if none are truthy): ‚ # Pair the current value with the (implicit) input-integer n Õ # Get the Euler's totient of both Ë # Check whether both are equal to each other # (after which the result is output implicitly) 

Most answers use \$n^2\$ as the range to check in, but this answer uses \$2n\$ instead to save a byte. If we look at the Mathematica implementation on the oeis sequence A066659 we can see it also uses the range \$[n+1, 2n+1)\$ to check in.

added 28 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#05AB1E, 11 10 9 7 bytes

L+.Δ‚ÕË 

-1 byte with help from @ExpiredData.
-2 bytes thanks to @Grimmy.

Outputs -1 if no \$m\$ exists.

Try it online or verify all test cases.

Explanation:

L # Push a list in the range [1, (implicit) input-integer n] + # Add the (implicit) input-integer n to each to make the range [n+1, 2n] .Δ # Get the first value of this list which is truthy for  # (or results in -1 if none are truthy): ‚ # Pair the current value with the (implicit) input-integer n Õ # Get the Euler's totient of both Ë # Check whether both are equal to each other # (after which the result is output implicitly) 

Most answers use \$n^2\$ as the range to check in, but this answer uses \$2n\$ instead to save a byte. If we look at the Mathematica implementation on the oeis sequence A066659 we can see it also uses the range \$[n+1, 2n+1)\$ to check in.

#05AB1E, 11 10 9 7 bytes

L+.Δ‚ÕË 

-1 byte with help from @ExpiredData.
-2 bytes thanks to @Grimmy.

Outputs -1 if no \$m\$ exists.

Try it online or verify all test cases.

Explanation:

L # Push a list in the range [1, (implicit) input-integer n] + # Add the (implicit) input-integer n to each .Δ # Get the first value of this list which is truthy for (or -1 if none are truthy): ‚ # Pair the current value with the (implicit) input-integer n Õ # Get the Euler's totient of both Ë # Check whether both are equal to each other # (after which the result is output implicitly) 

Most answers use \$n^2\$ as the range to check in, but this answer uses \$2n\$ instead to save a byte. If we look at the Mathematica implementation on the oeis sequence A066659 we can see it also uses the range \$[n+1, 2n+1)\$ to check in.

#05AB1E, 11 10 9 7 bytes

L+.Δ‚ÕË 

-1 byte with help from @ExpiredData.
-2 bytes thanks to @Grimmy.

Outputs -1 if no \$m\$ exists.

Try it online or verify all test cases.

Explanation:

L # Push a list in the range [1, (implicit) input-integer n] + # Add the (implicit) input-integer n to each to make the range [n+1, 2n] .Δ # Get the first value of this list which is truthy for  # (or results in -1 if none are truthy): ‚ # Pair the current value with the (implicit) input-integer n Õ # Get the Euler's totient of both Ë # Check whether both are equal to each other # (after which the result is output implicitly) 

Most answers use \$n^2\$ as the range to check in, but this answer uses \$2n\$ instead to save a byte. If we look at the Mathematica implementation on the oeis sequence A066659 we can see it also uses the range \$[n+1, 2n+1)\$ to check in.

deleted 690 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#05AB1E, 11 10 9 9 7 bytes

nŸDÕ¬QϦнL+.Δ‚ÕË 

-1 byte with help from @ExpiredData.
-2 bytes thanks to @Grimmy.

Outputs an empty string-1 if no \$m\$ exists.

Try it onlineTry it online or verify all test casesverify all test cases.

Explanation:

n # Square the (implicit) input-integer n Ÿ L # Pop and pushPush a list in the range [n[1, n²] D # Duplicate(implicit) thisinput-integer listn]   Õ+ # TakeAdd the Euler Totient of each(implicit) valueinput-integer inn thisto listeach   ¬  # PushGet the first elementvalue of the list (without popping thethis list itself)  Q which #is Checktruthy for each(or element-1 if it's equal to thisnone firstare elementtruthy):   Ï # Only keep the values atPair the truthycurrent indicesvalue inwith the list we've duplicated  # (will only yield theimplicit) input-integer n itself if no m was found)   ¦Õ # Remove Get the firstEuler's elementtotient of this list (so becomes empty when no m was found)both   нË # And only leave the first valueCheck (orwhether anboth emptyare stringequal forto emptyeach lists)other   # (after which the result is output implicitly) 

Could have been 7Most answers use bytes if we'd be allowed\$n^2\$ as the range to outputcheck in, but this answer uses \$n\$ itself when no\$2n\$ instead to save a byte. If we look at the \$m\$ is found with:

nŸÕćk>+ 

Try it online orMathematica implementation on the oeis sequence A066659 we can see it also uses the range verify all test cases\$[n+1, 2n+1)\$ to check in.

#05AB1E, 11 10 9 bytes

nŸDÕ¬QϦн 

-1 byte with help from @ExpiredData.

Outputs an empty string if no \$m\$ exists.

Try it online or verify all test cases.

Explanation:

n # Square the (implicit) input-integer n Ÿ  # Pop and push a list in the range [n, n²] D # Duplicate this list   Õ # Take the Euler Totient of each value in this list   ¬ # Push the first element of the list (without popping the list itself)  Q  # Check for each element if it's equal to this first element   Ï # Only keep the values at the truthy indices in the list we've duplicated  # (will only yield the input n itself if no m was found)   ¦ # Remove the first element of this list (so becomes empty when no m was found)   н # And only leave the first value (or an empty string for empty lists)   # (after which the result is output implicitly) 

Could have been 7 bytes if we'd be allowed to output \$n\$ itself when no \$m\$ is found with:

nŸÕćk>+ 

Try it online or verify all test cases.

#05AB1E, 11 10 9 7 bytes

L+.Δ‚ÕË 

-1 byte with help from @ExpiredData.
-2 bytes thanks to @Grimmy.

Outputs -1 if no \$m\$ exists.

Try it online or verify all test cases.

Explanation:

L # Push a list in the range [1, (implicit) input-integer n] + # Add the (implicit) input-integer n to each  # Get the first value of this list which is truthy for (or -1 if none are truthy):  # Pair the current value with the (implicit) input-integer n Õ #  Get the Euler's totient of both Ë # Check whether both are equal to each other # (after which the result is output implicitly) 

Most answers use \$n^2\$ as the range to check in, but this answer uses \$2n\$ instead to save a byte. If we look at the Mathematica implementation on the oeis sequence A066659 we can see it also uses the range \$[n+1, 2n+1)\$ to check in.

deleted 791 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
added 1138 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
deleted 470 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading