[Question]
  [
[Giuga numbers](https://en.wikipedia.org/wiki/Giuga_number) ([A007850](https://oeis.org/A007850)) are composite numbers \$n\$ such that, for each prime factor \$p\_i\$ of \$n\$, \$p\_i \mid \left( \frac n {p\_i} -1 \right)\$. That is, that for each prime factor \$p\_i\$, you can divide \$n\$ by the factor, decrement it and the result is divisible by \$p\_i\$
For example, \$n = 30\$ is a Giuga number. The prime factors of \$30\$ are \$2, 3, 5\$:
* \$\frac {30} 2 - 1 = 14\$, which is divisible by \$2\$
* \$\frac {30} 3 - 1 = 9\$, which is divisible by \$3\$
* \$\frac {30} 5 - 1 = 5\$, which is divisible by \$5\$
However, \$n = 66\$ isn't, as \$\frac {66} {11} - 1 = 5\$ which is not divisible by \$11\$.
The first few Giuga numbers are \$30, 858, 1722, 66198, 2214408306, ...\$
---
Given a positive integer \$n\$, determine if it is a Giuga number. You can output either:
* Two distinct, consistent values to indicate whether \$n\$ is a Giuga number or not (e.g `True`/`False`, `1`/`0`, `5`/`"abc"`)
* Two classes of values, which are naturally interpreted as truthy and falsey values in your language (e.g. `0` and non-zero integers, and empty vs non-empty list etc.)
Additionally, you may choose to take a [black box function](https://codegolf.meta.stackexchange.com/a/13706/66833) \$f(x)\$ which returns 2 distinct consistent values that indicate if its input \$x\$ is prime or not. Again, you may choose these two values.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins.
---
## Test cases
```
   1 -> 0
  29 -> 0
  30 -> 1
  66 -> 0
 532 -> 0
 858 -> 1
1722 -> 1
4271 -> 0
```
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
Æfḟɓ÷’ọȦ
```
[Try it online!](https://tio.run/##ASIA3f9qZWxsef//w4Zm4bifyZPDt@KAmeG7jcim/8i3NMOHxof/ "Jelly – Try It Online")
This version is mostly caird's, and I merged one of my golfs into it. Posted with their permission.
```
Æfḟɓ÷’ọȦ    Main Link
Æf          Take the prime factors
  ḟ         And filter out the original (if x is prime, this list is empty, otherwise, nothing changes)
   ɓ----    Call this chain dyadically with reversed arguments: x on the left, factors on the right
    ÷       Divide x by each factor
     ’      Decrement each quotient
      ọ     Count divisibility of each result by the corresponding factor
       Ȧ    Are any and all truthy? That is, the list is all truthy and is not empty
```
This was my original solution:
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
:’ọɗÆfȦ>Ẓ
```
[Try it online!](https://tio.run/##ASIA3f9qZWxsef//OuKAmeG7jcmXw4ZmyKY@4bqS/8i3NMOHxof/ "Jelly – Try It Online")
Gives `1` for Guiga numbers and `0` otherwise.
```
:’ọɗÆfȦ>Ẓ    Main Link (monadic)
---ɗ         Last three links as a dyad
    Æf       Monad - get array of prime factors
:’ọ          Since this is a 2,1-chain, this dyadic section is called with `x` on the left and the prime factors on the right
:            - divide x by each prime factor
 ’           - decrement each
  ọ          - how many times is each result divisible by its matching prime factor?
      Ȧ      Check if all are true
       >Ẓ    2,1-chain: check if that result is greater than whether or not x is prime (in other words, true if and only the above check was true and it is not a prime)
```
[Answer]
# [Zsh](https://www.zsh.org) `-eo extendedglob` 36 bytes
```
>`factor $1`
for x (<->~$1)$[$1/x%x]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PY5LDoIwGIT3nOJfVEM1BP8iDy2BgxgTVAouEAwUbXxdxA2J8RSehNsIkriaSebLzDxfl2rftFvUqV4JCVPBk81OFiUQvKWlOIJx7iz3fZ-ElCddgKAjsAVYM3AcsC0Gnu0BuozBnLlIr78iQxQglBR5LOI0K7b8XcvE8FoSRP-BSOv7FOi-ETwIUrIiaKqRWg_sh44DMxYnM6-zTOsf4JKEvDzA5D4QTTPoFw)
Outputs via exit code: zero for Giuga numbers and non-zero otherwise.
This makes *heavy* abuse of the rule
> 
> Additionally, you may choose to take a black box function f(x) which returns 2 distinct consistent values that indicate if its input x is prime or not. Again, you may choose these two values.
> 
> 
> 
The function is assumed to:
* be predefined under the name `1`
* output either `0` or `1` to standard out, for prime and non-prime respectively
* always succeed (exit with a status code of 0)
For each prime factor `x`, `$[$1/x%x]` takes the residue of the input mod `x` and tries to execute it as a command. The only number that's defined as a command is the black-box function `1`, which will succeed; otherwise, the command fails, and because of the `-e` option, Zsh exits with a non-zero status code.
---
If this is cheating, have this:
# [Zsh](https://www.zsh.org), 40 bytes
```
>`factor $1`
for x (<->~$1)(($1/x%x==1))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PY5LDoIwGIT3nuJfVNNqCP5FHloeV0Gk4ALBQFHi6yJuSIyn8CTcRpDE1UwyX2bm-bpU-7aLkDJaSQULKZLtThUlELylpTyCdu6tcF2XBEwkfYBAEfgajCVYFpgGB8d0AG3OYcVtZNdfkSYLkI2SeSzjNCsi8a5Vojkd9cP_QDgZ-hqgruY_CDJKCerNtPE8ZGzkP2zm67E86XmdZZPhBW5IIMoDzO8j0bajfgE)
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `r`, 8 bytes
```
Ǐo:?/‹ḊΠ
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=r&code=%C7%8Fo%3A%3F%2F%E2%80%B9%E1%B8%8A%CE%A0&inputs=2&header=&footer=)
```
Ǐo       # prime factors excluding x
  :      # Duplicate
   ?/    # Input / n (vectorised)
     ‹   # Decremented (vectorised)
      Ḋ  # Is divisible by corresponding prime factor (vectorised)
       Π # Take the product (0 for empty list)
```
[Answer]
# [J](http://jsoftware.com/), 22 19 bytes
```
1<q:(-:*#@[)*:@q:|]
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DW0KrTR0rbSUHaI1tawcCq1qYv9rcvk56SlEW2lo62tp6WsWWtlCZbhKUotLgMakcaUmZ@QDTbFVAIkoGKLxjSwhAoYwAWMDNBVmZmgCpsZGaHosTC3QRAzNjYzQtJkYmRv@BwA "J – Try It Online")
-3 after reading [Bubbler's analysis](https://codegolf.stackexchange.com/a/230822/15469).
* `*:@q:|]` Mods input by square of its prime factors (vectorized).
* `-:` Does that match the list of prime factors?
* `*#@[` Times the length of the prime factors.
* `1<` Is that greater than 1?
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~73~~ 62 bytes
```
.+
$*
^((.)*)(?=\1*$)(?<!^\3+(..+))(?!((?<-2>\1)+)(?(2)^)\4*$)
```
[Try it online!](https://tio.run/##DYq9CoQwEAb77y0Ehd0Eg7vxF/wpfYkQtLjiGovj3j9uNcwwv8//@9ylofMqwaN2yESBHdOxJXG1ca1yip5C8GxWkZVW9yTsTUk5c@ptLKWDQBfEDuOIISrmYYZMquh1khc "Retina 0.8.2 – Try It Online") Link includes test cases. Outputs `0` for a Guiga number, `1` if not. Explanation:
```
.+
$*
```
Convert `n` to unary.
```
^((.)*)
```
Match an integer `p=\1`, but also as a count `\2`, where...
```
(?=\1*$)
```
... `p` must be a factor of `n`, ...
```
(?<!^\3+(..+))
```
... `p` must not have a nontrivial proper factor `\3`, and...
```
(?!((?<-2>\1)+)(?(2)^)\4*$)
```
... `n-p` must be zero (in which case `n` is not composite) or not divisible by `p²`, which is calculated by matching `\1` `\2` times, and then captured, so that it can be easily repeated using `\4`.
Edit: Saved 11 bytes thanks to @Deadcode pointing out that I don't need to check that `p` is at least `2`, and in fact also allowing `p=0` means that the program works for `n=0` (although not required by the question) at no extra cost.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
Æfð_ọḟ>1Ȧ
```
[Try it online!](https://tio.run/##y0rNyan8//9wW9rhDfEPd/c@3DHfzvDEsv@H2x81rfn/P9pQR8HQVEfByFJHwdhAR8HMTEfB1NhIR8HC1AIoY24EZJoYmRvGAgA "Jelly – Try It Online")
```
Æfḟð_ọḷ’Ȧ
```
[Try it online!](https://tio.run/##y0rNyan8//9wW9rDHfMPb4h/uLv34Y7tjxpmnlj2/3D7o6Y1//9HG@ooGJrqKBhZ6igYG@gomJnpKJgaG@koWJhaAGXMjYBMEyNzw1gA "Jelly – Try It Online")
I already lost, but figured I'd post them since they're somewhat different 9-byters.
### How these work
The condition \$p\_i \mid \left( \frac n {p\_i} -1 \right)\$ can be translated to
$$
\frac{n}{p\_i}-1 \equiv 0 \quad(\operatorname{mod} \ p\_i) \\
\frac{n}{p\_i} \equiv 1 \quad(\operatorname{mod} \ p\_i) \\
n \equiv p\_i \quad(\operatorname{mod} \ p\_i^2)
$$
So \$n-p\_i\$ (equivalently, \$p\_i-n\$) must be divisible by \$p\_i\$ at least twice.
```
Æfð_ọḟ>1Ȧ    Monadic link; input = n
Æf           List of prime factors of n (= L)
  ð......    Call ... as a dyadic chain, left = L, right = n
    ọ        How many times each of...
   _         L - n
             ...is divisible by...
     ḟ       Remove any occurrences of n from L
             (missing positions are treated as 0, so ọ gives 0)
      >1Ȧ    Test if the result is nonempty list of all 2s or above
Æfḟð_ọḷ’Ȧ    Monadic link; input = n
Æfḟ          Remove any occurrences of n from prime factors of n (= L)
   ð.....    Call ... as a dyadic chain, left = L, right = n
    _ọḷ      How many times each of L-n is divisible by each of L
       ’Ȧ    Test if the result, decremented, is nonempty with all nonzero
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 50 bytes
```
->n{(2...z=n).all?{|c|z%c>0||n/c%c==1&&z/=c}&&z<n}
```
[Try it online!](https://tio.run/##DcWxDkAwEADQX7FoSM5pD6nB8SFi4BITjUgMqr69vOWd13LHlWPRuycjRPTscpy3bXiCBJ9Kr0NwpaTCbJTyJcv717k3HslogDRUGpqKoG1aMJYIarJmwn0@MrXm8QM "Ruby – Try It Online")
### So what?
```
->n{(2...z=n).all?
```
Check every number between 2 and n-1, use a temporary variable to skip over composite divisors.
```
{|c|z%c>0
```
If c is divisor of `z` then it's also a prime divisor of `n`, if not we can skip this number.
```
||n/c%c==1
```
Check if `n/c-1` can be divided by `c`
```
&&z/=c}
```
At this point, we must divide `z` by `c` before continuing. Once is enough, because if `n/c-1` can be divided by `c`, then `n` can't be divided by `c` more than once.
```
&&z<n}
```
Final check: did we divide z at least once? If not, then n is a prime number.
[Answer]
# [Python 2](https://docs.python.org/2/), 85 bytes
```
e=n=input();k=w=0;i=1
while~-n:
 i+=1
 while n%i<1:k+=(e/i-1)%i;n/=i;w+=1
print k<1<w
```
[Try it online!](https://tio.run/##HcpLCoAgFEbheatwEiQRdRtIpXc5Qj/GTcKQJm3dHsPzceKV1l3GUjwLQ@KZGm0DZx4smKq8YvN3J0ul0L6tflBSw9ESWm58j450DSs9w@bviQckqeDI5VKMoXl6AA "Python 2 – Try It Online")
-14 bytes thanks to @ovs
[Answer]
# JavaScript (ES6), ~~59 56~~ 53 bytes
Returns a Boolean value.
```
n=>(k=2,g=j=>j%k?k++<j&&g(j):n/k%k-1?g:1+g(j/k))(n)>1
```
[Try it online!](https://tio.run/##DcpBDoMgEEDRvaeYjQRCreBSHTyLsULKmJlGm26anp2y@3n5ef2s13Y@X@@O5bGXiIUxaMLhljBjyC0tZO2clUo6m5F7aqnzSxq9rdCTMZpN8CXKqRkQ/AQMMwzOuVrWGvg2ALFOoBRswpcc@/2QVGVqfuUP "JavaScript (Node.js) – Try It Online")
### Commented
```
n => (           // n = input
  k = 2,         // k is the prime divisor, starting at 2
  g = j =>       // g is a recursive function taking the quotient j
    j % k ?      //   if k is not a divisor of j:
      k++ < j && //     stop if k is greater than or equal to j
      g(j)       //     otherwise, do a recursive call with j unchanged
                 //     and k + 1
    :            //   else:
      n / k % k  //     if (n / k) modulo k
      - 1 ?      //     is not equal to 1:
        g        //       stop the recursion and yield g, which turns the
                 //       result into a non-numeric string and forces the
                 //       final test to fail, whatever happened before
      :          //     else:
        1 +      //       add 1 to the result
        g(j / k) //       do a recursive call with j = j / k
)(n)             // initial call with j = n
> 1              // return true if there were at least 2 prime divisors
                 // satisfying the Giuga test
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
f©/<0K®Öß
```
Outputs `1` as truthy and either `0`/`""` as falsey.
[Try it online](https://tio.run/##yy9OTMpM/f8/7dBKfRsD70PrDk87PP//f2MDAA) or [verify some more test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXL/7RDK/VtDLwPrTs87fD8/zr/ow11jCx1jA10zMx0TI2NdEwtTHUMzY2MdEyMzA1jAQ).
**Explanation:**
```
f          # Get all unique prime factors of the (implicit) input
 ©         # Store this list in variable `®` (without popping)
  /        # Divide the input by each of these
   <       # Decrease it by 1
    0K     # Remove all 0s
      ®Ö   # Check of each if it's divisible by their initial values `®`
        ß  # Pop and push the minimum of this list ("" for empty lists)
           # (after which it is output implicitly as result)
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 16 bytes
```
N⁰ḋṀ{;N⁰↔÷;?%}ᵛ1
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/3@9R44aHO7of7myotgaxH7VNObzd2l619uHW2Yb//1uYWgAA "Brachylog – Try It Online")
[Answer]
# Regex (ECMAScript 2018 / Python[`regex`](https://bitbucket.org/mrabarnett/mrab-regex/src/hg/) / .NET), ~~83~~ ~~79~~ ~~64~~ 49 bytes
```
^(x(x*))(?<!^\3+(x+x))(?!(?=\1*(\1\2+$))\4*$)\1*$
```
*-15 bytes (79 → 64) thanks to H.PWiz*  
*-8 bytes (64 → 56) by squaring instead of doing division (thanks to H.PWiz [for the idea](https://chat.stackexchange.com/transcript/message/61553870#61553870))*  
*-7 bytes (56 → 49) [thanks to H.PWiz](https://chat.stackexchange.com/transcript/message/61554305#61554305) - now beats the original .NET-only version!*
Returns a non-match for Giuga numbers.
[Try it online!](https://tio.run/##TY5Bb8IwDIXv/AqokGJTGjVABaIETjtw2WE7rkNEJRRPXdolASoBv52VSZO4WLa/5@f3pU7K5ZZqH5lqp@9OxqmVb7p4aWp495ZMwa06b@8baKAZIMJq0dtk4xCasHlMPVjJTAwgE9ko7CNmk0Ef20X/vuWupFyDGEYCMbX650hWA7Na7UoymiHP297rtfHa7lUrvZCpj35e2yrXznHnd2RuyCsD7O9iWMrlpZAld3VJHljEMKU9gJEFL7Up/AGXo@uV3Kt6BZK1su7hDsVH/In4D/QzMEuxEvMHRn@w1TlYm5Mqade1yhR63g3CMt1XFlJaSJ1SGGL7sBc0Abe6btMDIf9WPj@ARbw8Ja@Onp8teQ3gViwzbM4YhoSpkyK93fAuIhHHnWQcR8k46cySOJpN446YjuKoLUlnMpqKXw "JavaScript (Node.js) – Try It Online") - ECMAScript 2018  
[Try it online!](https://tio.run/##LY7RjoIwFETf@xXXhodeoKQFCQa28UNEE7NWbcIWUvpQ@Xmkui83dyZnJjO9/HO01Wr@ptF5mF9z7vRDhw6ccpTS9cICCykiO/7sLn2VsZCFqHbsqHqZsl72ZZYg9vs0wc1I1i11ki2X5w4WJch9dDCAsbG7mP3N2JbAoIZingbjGeUUCUTIRshd7UMzYz0bTuKM@ffbyjCTuAXB3MGOHj4ji1lf3e@TuRxooKn9AJFYWphcjGI0FiW7f21zbW@KUlwll0KQuhK8rmpyqAU/NILIphR8OzXZl418Aw "Python 3 – Try It Online") - Python `import regex` (very slow)  
[Try it online!](https://tio.run/##RY/RaoMwFIbvfQqVAyZmKYlWLHXSwq73BGpBXDoDWSKaolR8dqeFsZsD38fPz386M4p@aIVSK/R50YtvMVXnsxYjugbrDU1oCjFGl3fvVsYETWTayUOXvOQhKnkZEcC4PIaANwFrcH3zP8xPJ5X48nEGz5xld9OLumkRKFdqF6TuHhbPUOeg6NApaX3qZ/KOoD405qEtVdaN9gDJoS5YtWwFCHReSG2rl8lAUyX@mO9MCJ63Dg/6w2dtm1YMKJiCEDR@eXjieeylFbQ1g122XTz7Z5dqs72spBYu6GVZVk45Y04SM5rEiXNKGD2lzOFpxOh2EucYpfwX "PowerShell – Try It Online") - .NET
The commented version below is a **54 byte** version that behaves correctly with an input of zero, and returns a match for Giuga numbers. (Its length would be 52 bytes if returning a non-match for Giuga numbers.)
The underlying squaring/multiplication algorithm is explained [in this post](https://codegolf.stackexchange.com/questions/125237/its-hip-to-be-square/223201#223201).
```
^                      # tail = N = input number
(?!                    # Negative lookahead - Assert that this cannot match
    # Cycle \1 through all the prime divisors of N
    (x(x*))            # \1 = conjectured non-composite divisor of N; \2 = \1-1
                       # tail -= \1; head = \1
    (?<!^\3+(x+x))     # Assert head is not composite, i.e. is prime or <2
    # Assert that tail is not divisible by \1 * \1
    (?!                # Negative lookahead - Assert that this cannot match
        # Calculate \4 = \1 * \1; this will fail to match if the result would
        # be greater than tail.
        (?=
            \1*        # We can use this shortcut thanks to tail already being
                       # checked for divisibility by \1 later.
            (\1\2+$)   # \4 = \1 * \1
        )
        \4*$           # Assert that tail is divisible by \4
    )
    \1*$               # Assert N is divisible by \1
)
x                      # Prevent N == 0 from matching
```
## Regex (.NET), ~~57~~ ~~53~~ bytes
Now obsoleted by the ECMAScript 2018 / .NET version above.
## Regex (ECMAScript+`(?^=)`[RME](https://github.com/Davidebyzero/RegexMathEngine)), 50 bytes
```
^(x(x*))(?^1!(xx+)\3+$)(?!(?=\1*(\1\2+$))\4*$)\1*$
```
[Try it on replit.com](https://replit.com/@Davidebyzero/regex-Giuga-numbers-with-lookinto) - RegexMathEngine
This is a port using lookinto instead of variable-length lookbehind.
# Regex (ECMAScript+`(?*)`[RME](https://github.com/Davidebyzero/RegexMathEngine) / PCRE2 v10.35+), 58 bytes
```
^(?*(x(x*))(\1*$))(?!\3(xx+)\4+$)\1(?!(?=\1*(\1\2+$))\5*$)
```
[Try it on replit.com](https://replit.com/@Davidebyzero/regex-Giuga-numbers-with-molecular-lookahead) - RegexMathEngine  
[Attempt This Online!](https://ato.pxeger.com/run?1=fVLdatswFIZd-ilOhKilxE6srMu6KiYMlo3CaIe3u7oTricnXhzZyAoYSp5kN4WxZ9izbE-z46QwlosJJB2d7-dIB3373qybx9_PXs8XGAC1EAOZEBhDY_VKWd1UWa6ZPxkPF0qts8qpvN42ZaVtylIu02TS-gH4OAtMqpXuCcZp41qm1Nur90uleACCoyUaS680pWq1Y6TJrR7fZ_nGWVxUVW5LRwIgoSBcwr80q_Odbcva_J_29QhFiHhFbRkt40jSKi7wWi37-OnN1TWX_AHKgtHqtnW20gYjHoq7OCapIRzJ7e4eEUwHURAK3ut111T1F81ISAKkS9Tn9c64XjufougWDXCN7qQHcKhsns7UzOMDjtFoxOEBCYAXADZgdBMfurzNXL5m1AZYt2-5zhzzOz-ghuMAqo-0Kmud0taiPR_E8Ydk-U5d36hlktwk8q8t3cDZGQyoxmL9Q0uu83Xdv04CNkRI6M9AjdyfinrNASSXQMYnRdW2XTHeF9p7-5O_gPkfO1eEF78uP7PFkHWsG3LOUjGkuC0G6XPWdSOeno8oTwUm2CJGEAnpFFM8fYHEo8Pj0_YzCsVFFHnn05fCm83EqyiczaYiOsJ_AA "PHP - Attempt This Online") - PCRE2 v10.40+
This is a port using molecular lookahead instead of variable-length lookbehind. It is far, far faster, since it does not place a divisibility test after an is-prime test (and to do so would not be better golf, as far as I can tell); on my PC it can test every number from \$0\$ to \$66200\$ in 5.2 minutes (whereas the ECMAScript 2018 version takes weeks or maybe more) and can even test \$2214408306\$ in 6.4 minutes.
```
^                      # tail = N = input number
(?!                    # Negative lookahead - Assert that this cannot match
    # Cycle \1 through all the prime divisors of N
    (?*(x(x*))(\1*$))  # Cycle \1 through all of the divisors of N, including N
                       # itself; \2 = \1-1; \3 = N-\1 == tool to make tail = \1
    (?!\3(xx+)\4+$)    # Assert \1 is prime or \1 < 2.
    \1                 # tail -= \1
    # Assert that tail is not divisible by \1 * \1
    (?!                # Negative lookahead - Assert that this cannot match
        # Calculate \5 = \1 * \1
        (?=
            \1*        # We can use this shortcut thanks to tail already being
                       # checked for divisibility by \1 later.
            (\1\2+$)   # \5 = \1 * \1
        )
        \5*$           # Assert that tail is divisible by \5
    )
)
x                      # Prevent N == 0 from matching
```
### \$\large\textit{Full programs}\$
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~63~~ ~~59~~ 55 bytes
```
.+
$*
^(.+)(?<!^\2+(.+.))(\1)*$(?<=(?!\B\1*$)(?>(?<-3>.)*))
```
Takes its input in decimal. Outputs `1` if input is a Guiga number, `0` if not.
[Try it online!](https://tio.run/##Fcg9CsMwDAbQ/btFwAHJBlHJ@YUEj72EMMnQoUuH0vu7yfje9/V7f87W0/NokhAiKglJZKayddVzIklyq6Oyu0ZydUuB2YcY@IrQmsJW5AemCWM2LOMCnc0w2Kx/ "Retina 0.8.2 – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~13~~ 12 bytes
```
YfG-t?6MU\~A
```
[Try it online!](https://tio.run/##y00syfmfoJCpUBLlp2CvUKGnEKsQ4fE/Ms1dt8TezDc0ps7xfyxQwkNBXTVFIbNYIVHBPbM0PVEhrzQ3KbVIXSHSRaEWIZuXX4JNBdBMF4WoCoWQ2P@GXEaWXMYGXGZmXKbGRlwWphZchuZGRlwmRuaGXAb6BgA "MATL – Try It Online")
1 for Giuga number, either 0 or an empty vector for non-Giuga number - both of which MATL considers falsy.
*(note: had previously posted a 9 byte version which was wrong)*
**Explanation**:
\$p\_i \mid \left( \frac n {p\_i} -1 \right) \Longrightarrow p\_i^2 \mid \left( n - {p\_i} \right) \Longrightarrow p\_i^2 \mid \left( {p\_i} - n \right)\$
1. `Yf` - get the prime factors of the input (if `1` is the input, `Yf` returns an empty vector; primes return themselves)
2. `G-` - subtract the input from each factor (let's call this S = \${p\_i} - n \$)
3. `t?` - is it truthy? (for `1` this is an empty vector; for primes it's a 0; either way, falsey)
4. `6M` - If so, bring back a copy of the list of factors
5. `U` - square each one
6. `\` - compute the mod of S with respect to these squares
7. `~A` - And check if that is all 0s
If the check at step 3 failed, that falsy S is left on the stack. If it succeeded, the result of the final step is left on the stack.
---
Alternate 12 byter: `_tYf+t5MU\~*` [Try it online!](https://tio.run/##y00syfmfoJCpUBLlp2CvUKGnEKsQ4fE/viQyTbvE1Dc0pk7rv72Ch4K6aopCZrFCooJ7Zml6okJeaW5SapG6QqSLQi1CNi@/BJsKoIkuClEVCiGx/w25jCy5jA24zMy4TI2NuCxMLbgMzY2MuEyMzA25DPQNAA "MATL – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 18 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
k f<U £/XÉ vXÃâ ¥1
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=ayBmPFUgoy9YySB2WMPiIKUx&input=WzEsMjksMzAsNjYsNTMyLDg1OCwxNzIyLDQyNzFdLW0)
```
k     - prime factors
f<U   - filter out U(input)
£..Ã  - map X-> :
/XÉ     > U/X-1
vX      > divisible by X?
â     - get unique elements
¥1    - is [1] ?
```
]