[Question]
  [
### Background:
The current [Perfect Numbers challenge](https://codegolf.stackexchange.com/q/58026/76162) is rather flawed and complicated, since it asks you to output in a complex format involving the factors of the number. This is a purely [decision-problem](/questions/tagged/decision-problem "show questions tagged 'decision-problem'") repost of the challenge.
## Challenge
Given a positive integer through any [standard input format](https://codegolf.meta.stackexchange.com/q/2447/76162), distinguish between whether it is perfect or not.
A perfect number is a number that is equal to the sum of all its proper divisors (its positive divisors less than itself). For example, \$6\$ is a perfect number, since its divisors are \$1,2,3\$, which sum up to \$6\$, while \$12\$ is not a perfect number since its divisors ( \$1,2,3,4,6\$ ) sum up to \$16\$, not \$12\$.
### Test Cases:
```
Imperfect:
1,12,13,18,20,1000,33550335
Perfect:
6,28,496,8128,33550336,8589869056
```
### Rules
* Your program doesn't have to complete the larger test cases, if there's memory or time constraints, but it should be theoretically able to if it were given more memory/time.
* Output can be two distinct and consistent values through any [allowed output format](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods). If it isn't immediately obvious what represents Perfect/Imperfect, please make sure to specify in your answer.
  
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 4 bytes
```
fk+?
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRuX/2obcOjpuZHHcuVSopKU/UUNAJSi9JSk0s0lWpAgmmJOcUgUc/cAph47cNdnbUPt074n5atbf//f7ShjpmOoZGOkYWOobGOiSWQY6FjYQjkGhnoGBubmhoYGwPFDAwMYgE "Brachylog ‚Äì Try It Online")
The predicate succeeds for perfect inputs and fails for imperfect inputs, printing `true.` or `false.` if run as a complete program (except [on the last test case](https://tio.run/##SypKTM6ozMlPN/r/Py1b2/7/fwtTC0sLM0sDUzMA) which takes more than a minute on TIO).
```
        The input's
f       factors
 k      without the last element
  +     sum to
   ?    the input.
```
[Answer]
# [Neim](https://github.com/okx-code/Neim), 3 bytes
```
ùêïùê¨ùîº
```
[Try it online!](https://tio.run/##y0vNzP3//8PcCVOBeM2HuVP2/P9vYWphaWFmaWBqBgA "Neim ‚Äì Try It Online")
(I don't actually know how to run all of the test cases at once, since I started learning Neim about fifteen minutes ago, but I did check them individually.)
Prints 0 for imperfect, 1 for perfect.
```
ùêï      Pop an int from the stack and push its proper divisors,
       implicitly reading the int from a line of input as the otherwise absent top of the stack.
 ùê¨     Pop a list from the stack and push the sum of the values it contains.
  ùîº    Pop two ints from the stack and push 1 if they are equal, 0 if they are not;
       implicitly reading the same line of input that was already read as the second int, I guess?
       Implicitly print the contents of the stack, or something like that.
```
[Answer]
# [R](https://www.r-project.org/), ~~33~~ 29 bytes
```
!2*(n=scan())-(x=1:n)%*%!n%%x
```
[Try it online!](https://tio.run/##K/r/X9FISyPPtjg5MU9DU1NXo8LW0CpPU1VLVTFPVbXiv6HRfwA "R ‚Äì Try It Online")
Returns `TRUE` for perfect numbers and `FALSE` for imperfect ones.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) `-!`, 4 bytes
```
¬•√¢¬¨x
-----------------
            Implicit Input U
¬•           Equal to
   x        Sum of
 √¢          Factors of U
  ¬¨         Without itself
```
*For some reason `¬¶` doesnt work on tio so I need to use the `-!` flag and `¬•` instead*
[Try it online!](https://tio.run/##y0osKPn//9DSw4sOran4/9/Y2NTUwNjYTEFXEQA "Japt ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 bytes
```
√Ü·π£=
```
[Try it online!](https://tio.run/##y0rNyan8//9w28Odi23/H25/1LTG/f//aEMdQyMdQ2MdQwsdIwMdQwMDAx1jY1NTAyChY6ZjZKFjYmmmY2EIZECFgTxTC0sLM0sDU7NYAA "Jelly ‚Äì Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 46 bytes
```
lambda x:sum(i for i in range(1,x)if x%i<1)==x
```
[Try it online!](https://tio.run/##Xc69DoIwEMDx2T7FBWPSJje0YJtC5AHc3NUBleoR@Qhigk9fISpRlxsu/1/umkd3qavIu3Tnr1l5OGXQJ7d7yQlc3QIBVdBm1TnnCntBDvoFrZRI095T2eSty48dpLBVqEJUESqLoUQlpdzDHCGKtJbDYOyrNRhaXMYGrQrtmL2rYaFtbE0stRlAS1XHg/XnShIINr003U7Y7BUSguMkxAQ3v6wY2T8qRlQMyD8B "Python 3 ‚Äì Try It Online")
Brute force, sums the factors and checks for equality.
[Answer]
# [Python](https://docs.python.org/2/), 45 bytes
```
lambda n:sum(d*(n%d<1)for d in range(1,n))==n
```
`True` for perfect; `False` for others (switch this with `==` -> `!=`)
**[Try it online!](https://tio.run/##NZPLbttADEXXzVcMUBSxCwYYcmY0mqDpN3TfduFAsmMglgJZSZuvdw8ddOXnvTw@pF/e16d5ssv@4dfleXd6HHZhuj@/njbD1830Zfim2/28hCEcp7DspsO4UZm224eH6fI5LONpfhuH8Hg8hHU8r@ewzmH3Nh@HsB5P4/zKO5vdNIQTX1zew7gsdNH04zo0WLgL69MYDuM0LruVz97G5Xzkk3n/MU3C3@tj@DO/Pg//u5/G87i9cS6f6oVQqYkm0V4sisYYpRPrJbdOerV@e3/z6WU5Tus1IuH27vuthP3GX20vP4lnlURFNekSHUlaFkuZ3iLaiZZOcqW/SmUGczQ2sdxIRkkUVJXOSJo0ChIsRppwKZIp6DuplSQlkYZMQ2qSoK3AKkmVRoFTGGkPZ8kU9EUqv8YpIg2OkWhgdNekiySjNAqcwj40lCSZgj5LLSQpiTQ4RqruRbteCgWtSaPAKezDYTHJ7jFJRYBTRBocI9HA6K5KoaD10iPAKdw44aKSKehNKgKcItLgGIkGRnedFApalR58p1DShEsU9Guvgn5zCvybY7CAq/8i@FdfJvhOwQJcfRPsax8F@@YQ6DenSF5AMAv6tRVBvzkE/hmMfeRrbYJ8cwbsm0MkXwHBJNhXjgD75gzoZy7yca/cAO4tOj8FDoF9l88NIF@5AeSbM2CfubhHvXICnd8o@OSdITkAORXUKxeAenME3DMW84hXDgDxxv4Rb45g7Xrq7B/xyv4Rb06AeabiHe3K@tFubB/t5gTunbFsH@3K9nsHpwLvfnZJ/OpZPtKN3SPdnMCtEy3@p@JZE6zbdfXkyZEmzupxbmwe5@YELp0om/eTZ/NINyfAupX4@x8 "Python 2 ‚Äì Try It Online")**
**~~44 42~~ 41 bytes** (-2 thanks to ovs) if we may output using "truthy vs falsey":
```
f=lambda n,i=1:i/n or-~f(n,i+1)-(n%i<1)*i
```
(falsey (`0`)) for perfect; truthy (a non-zero integer) otherwise
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 25 bytes
```
@(n)~mod(n,t=1:n)*t'==2*n
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999BI0@zLjc/RSNPp8TW0CpPU6tE3dbWSCvvf2JRUWJlWmmeRpqOQrShjqGRjqGxjqGFjpGBjqGBgYGOsbGpqQGQiNXkQlFqpmNkoWNiaaZjYQhkQFWZxWr@BwA "Octave ‚Äì Try It Online")
### Explanation
```
@(n)~mod(n,t=1:n)*t'==2*n
@(n)                        % Define anonymous function with input n
             1:n            % Row vector [1,2,...,n]
           t=               % Store in variable t
     mod(n,     )           % n modulo [1,2,...,n], element-wise. Gives 0 for divisors
    ~                       % Logical negate. Gives 1 for divisors
                  t'        % t transposed. Gives column vector [1;2;...;n]
                 *          % Matrix multiply
                      2*n   % Input times 2
                    ==      % Equal? This is the output value
```
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 46 bytes
```
n=>Enumerable.Range(1,n).Sum(x=>n%x<1?x:0)^n*2
```
Returns 0 if perfect, otherwise returns a positive number. I don't know if outputting different types of integers are allowed in place of two distinct truthy and falsy values, and couldn't find any discussion on meta about it. If this is invalid, I will remove it.
[Try it online!](https://tio.run/##DcuxCsIwEADQvV8RCkJiY0nEqcnFSScnHdyEGlI5sCekDQRKvz12eOPz08FPWK6JvEWa5cYNUAjchdIYYv/@hvbe0ydwLUm0jzTyDI522epz7pR40f5YTDX8It8uQ9AGLWilDDaNqJ4R53BDCrxelDytDBxb9FpLlANHYbUw5Q8 "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), ~~49~~ 47 bytes
```
n=>Enumerable.Range(1,n).Sum(x=>n%x<1?x:0)==n*2
```
[Try it online!](https://tio.run/##DcwxCsIwFADQvacIBSGxsSTiZPLjpJOTDs5tSOVD@wNpC4HSs0ffAZ6fT37G8ljJW6RF9jGOboBC4O60TiF1/RjaV0ffwLUk0b7XiWdwdMhW3/JVCQA6nouphpj4f2AI2qAFrZTBphHVJ@ESnkiB15uSl52BY5vea4ly4CiEKT8 "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
[Answer]
# [Labyrinth](https://github.com/m-ender/labyrinth), 80 bytes
```
?::`}:("(!@
perfect:
{:{:;%"}
+puts; "
}zero: "
}else{(:
"negI"  _~
""""""{{{"!@
```
The Latin characters `perfect puts zero else neg I` are actually just comments\*.  
i.e. if the input is perfect a `0` is printed, otherwise `-1` is.
**[Try it online!](https://tio.run/##y0lMqizKzCvJ@P/f3soqodZKQ0lD0YGrILUoLTW5xIqr2qraylpVqZZLu6C0pNhaQYmrtiq1KN8KxEjNKU6t1rDiUspLTfdUUlCIr@NSAoPq6molRYf//y0MjSwA "Labyrinth ‚Äì Try It Online")**
---
\* so [this](https://tio.run/##y0lMqizKzCvJ@P/f3soqodZKQ0lD0YFLAQKsuKqtqq2sVZVqubRBfGsFJa5asASMUa1hxaUEYgCJ@DouJTCorq5WUnT4/9/C0MgCAA "Labyrinth ‚Äì Try It Online") or [this](https://tio.run/##y0lMqizKzCvJ@P/f3soqodZKQ0lD0YHLyTXcMchVwYqr2qraylpVqZZL28fRM8haQYmrVsHfTcEKxPD19POv1rDiUgpxDA1SUlCIr@NSAoPq6molRYf//y0MjSwA) work too...
```
?::`}:("(!@               ?::`}:("(!@
       :                  BEWARE :
{:{:;%"}                  {:{:;%"}
+    ; "                  +LAIR; "
}    : "                  } OF : "
}    {(:                  }MINO{(:
"    "  _~                "TAUR"  _~
""""""{{{"!@              """"""{{{"!@
```
### How?
Takes as an input a positive integer `n` and places an accumulator variable of `-n` onto the auxiliary stack, then performs a divisibility test for each integer from `n-1` down to, and including, `1`, adding any which do divide `n` to the accumulator. Once this is complete if the accumulator variable is non-zero a `-1` is output, otherwise a `0` is.
The `?::`}:(` is only executed once, at the beginning of execution:
```
?::`}:(                                                      Main,Aux
?       - take an integer from STDIN and place it onto Main  [[n],[]]
 :      - duplicate top of Main                            [[n,n],[]]
  :     - duplicate top of Main                          [[n,n,n],[]]
   `    - negate top of Main                            [[n,n,-n],[]]
    }   - place top of Main onto Aux                       [[n,n],[-n]]
     :  - duplicate top of Main                          [[n,n,n],[-n]]
      ( - decrement top of Main                        [[n,n,n-1],[-n]]
```
The next instruction, `"`, is a no-op, but we have three neighbouring instructions so we branch according to the value at the top of Main, zero takes us forward, while non-zero takes us right.
If the input was `1` we go forward because the top of Main is zero:
```
(!@                                                          Main,Aux
(   - decrement top of Main                             [[1,1,-1],[-1]]
 !  - print top of Main, a -1
  @ - exit the labyrinth
```
But if the input was greater than `1` we turn right because the top of Main is non-zero:
```
:}                                                           Main,Aux
:  - duplicate top of Main                         [[n,n,n-1,n-1],[-n]]
 } - place top of Main onto Aux                        [[n,n,n-1],[-n,n-1]]
```
At this point we have a three-neighbour branch, but we know `n-1` is non-zero, so we turn right...
```
"%                                                           Main,Aux
"  - no-op                                             [[n,n,n-1],[-n,n-1]]
 % - place modulo result onto Main                   [[n,n%(n-1)],[-n,n-1]]
   - ...i.e we've got our first divisibility indicator n%(n-1), an
   -    accumulator, a=-n, and our potential divisor p=n-1:
   -                                                 [[n,n%(n-1)],[a,p]]
```
We are now at another three-neighbour branch at `%`.
If the result of `%` was non-zero we go left to decrement our potential divisor, `p=p-1`, and leave the accumulator, `a`, as it is:
```
;:{(:""}"                                                    Main,Aux
;          - drop top of Main                                [[n],[a,p]]
 :         - duplicate top of Main                         [[n,n],[a,p]]
  {        - place top of Aux onto Main                  [[n,n,p],[a]]
           - three-neighbour branch but n-1 is non-zero so we turn left
   (       - decrement top of Main                     [[n,n,p-1],[a]]
    :      - duplicate top of Main                 [[n,n,p-1,p-1],[a]]
     ""    - no-ops                                [[n,n,p-1,p-1],[a]]
       }   - place top of Main onto Aux                [[n,n,p-1],[a,p-1]]
        "  - no-op                                     [[n,n,p-1],[a,p-1]]
         % - place modulo result onto Main           [[n,n%(p-1)],[a,p-1]]
           - ...and we branch again according to the divisibility
           -    of n by our new potential divisor, p-1
```
...but if the result of `%` was zero (for the first pass only when `n=2`) we go straight on to BOTH add the divisor to our accumulator, `a=a+p`, AND decrement our potential divisor, `p=p-1`:
```
;:{:{+}}""""""""{(:""}                                       Main,Aux
;                      - drop top of Main                    [[n],[a,p]]
 :                     - duplicate top of Main             [[n,n],[a,p]]
  {                    - place top of Aux onto Main      [[n,n,p],[a]]
   :                   - duplicate top of Main         [[n,n,p,p],[a]]
    {                  - place top of Aux onto Main  [[n,n,p,p,a],[]]
     +                 - perform addition            [[n,n,p,a+p],[]]
      }                - place top of Main onto Aux      [[n,n,p],[a+p]]
       }               - place top of Main onto Aux        [[n,n],[a+p,p]]
        """""""        - no-ops                            [[n,n],[a+p,p]]
                       - a branch, but n is non-zero so we turn left
               "       - no-op                             [[n,n],[a+p,p]]
                {      - place top of Aux onto Main      [[n,n,p],[a+p]]
                       - we branch, but p is non-zero so we turn right
                 (     - decrement top of Main         [[n,n,p-1],[a+p]]
                  :    - duplicate top of Main     [[n,n,p-1,p-1],[a+p]]
                   ""  - no-ops                    [[n,n,p-1,p-1],[a+p]]
                     } - place top of Main onto Aux    [[n,n,p-1],[a+p,p-1]]
```
At this point if `p-1` is still non-zero we turn left:
```
"%                                                           Main,Aux
"  - no-op                                             [[n,n,p-1],[a+p,p-1]]
 % - modulo                                          [[n,n%(p-1)],[a+p,p-1]]
   - ...and we branch again according to the divisibility
   -    of n by our new potential divisor, p-1
```
...but if `p-1` hit zero we go straight up to the `:` on the second line of the labyrinth (you've seen all the instructions before, so I'm leaving their descriptions out and just giving their effect):
```
:":}"":({):""}"%;:{:{+}}"""""""{{{                           Main,Aux
:                                  -                   [[n,n,0,0],[a,0]]
 "                                 -                   [[n,n,0,0],[a,0]]
                                   - top of Main is zero so we go straight
                                   -  ...but we hit the wall and so turn around
  :                                -                 [[n,n,0,0,0],[a,0]]
   }                               -                   [[n,n,0,0],[a,0,0]]
                                   - top of Main is zero so we go straight
    ""                             -                   [[n,n,0,0],[a,0,0]]
      :                            -                 [[n,n,0,0,0],[a,0,0]]
       (                           -                [[n,n,0,0,-1],[a,0,0]]
        {                          -              [[n,n,0,0,-1,0],[a,0]]
                                   - top of Main is zero so we go straight
                                   -  ...but we hit the wall and so turn around
         (                         -             [[n,n,0,0,-1,-1],[a,0]]
          :                        -          [[n,n,0,0,-1,-1,-1],[a,0]]
           ""                      -          [[n,n,0,0,-1,-1,-1],[a,0]]
             }                     -             [[n,n,0,0,-1,-1],[a,0,-1]]
                                   - top of Main is non-zero so we turn left
              "                    -             [[n,n,0,0,-1,-1],[a,0,-1]]
               %                   - (-1)%(-1)=0     [[n,n,0,0,0],[a,0,-1]]
                ;                  -                   [[n,n,0,0],[a,0,-1]]
                 :                 -                 [[n,n,0,0,0],[a,0,-1]]
                  {                -              [[n,n,0,0,0,-1],[a,0]]
                   :               -           [[n,n,0,0,0,-1,-1],[a,0]]
                    {              -         [[n,n,0,0,0,-1,-1,0],[a]]
                     +             -           [[n,n,0,0,0,-1,-1],[a]]
                      }            -              [[n,n,0,0,0,-1],[a,-1]]
                       }           -                 [[n,n,0,0,0],[a,-1,-1]]
                        """""""    -                 [[n,n,0,0,0],[a,-1,-1]]
                                   - top of Main is zero so we go straight
                               {   -              [[n,n,0,0,0,-1],[a,-1]]
                                {  -           [[n,n,0,0,0,-1,-1],[a]]
                                 { -         [[n,n,0,0,0,-1,-1,a],[]]
```
Now this `{` has three neighbouring instructions, so...
...if `a` is zero, which it will be for perfect `n`, then we go straight:
```
"!@                                                          Main,Aux
"   -                                        [[n,n,0,0,0,-1,-1,a],[]]
    - top of Main is a, which is zero, so we go straight
 !  - print top of Main, which is a, which is a 0
  @ - exit the labyrinth
```
...if `a` is non-zero, which it will be for non-perfect `n`, then we turn left:
```
_~"!@                                                        Main,Aux
_     - place a zero onto Main             [[n,n,0,0,0,-1,-1,a,0],[]]
 ~    - bitwise NOT top of Main (=-1-x)   [[n,n,0,0,0,-1,-1,a,-1],[]]
  "   -                                   [[n,n,0,0,0,-1,-1,a,-1],[]]
      - top of Main is NEGATIVE so we turn left
   !  - print top of Main, which is -1
    @ - exit the labyrinth
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 33 bytes
```
->n{(1...n).sum{|i|n%i<1?i:0}==n}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWsNQT08vT1OvuDS3uiazJk8108bQPtPKoNbWNq/2f0FpSbFCtKGOoZGOobGOoYWOkYGOoYGBQaxeYl6lfXVNSU1adElsrYKyZ25BalFaanIJF0SLmY6RhY6JpZmOhaGRBVB1Tg6y6gCI2v8A "Ruby ‚Äì Try It Online")
[Answer]
# JavaScript, 38 bytes
```
n=>eval("for(i=s=n;i--;)n%i||!(s-=i)")
```
[Try it online!](https://tio.run/##LYy9CsIwGAB3n0ILQgJfSn5sqJSvm08hDiGmGgmJNCFT3z12cDmOG@5jqsl29d/CYnq6tmCLOLtqAumWtBKPGePkGZtoPPttO5HM0NOOtoJ3AUKCUCBGkBwE5xyUGga@AzTIES5XDaPY5Z/141D6fXsz9k0qzjbFnILrQ3qRCseFVErp1H4 "JavaScript (Node.js) ‚Äì Try It Online")
(Last testcase timeout on TIO.)
[Answer]
# TI-BASIC (TI-84), ~~30~~ 23 bytes
```
:2Ans=sum(seq(Ans/Xnot(remainder(Ans,X)),X,1,Ans,1
```
~~Horribly inefficient, but it works.~~  
Reducing the bytecount sped up the program by a lot.  
Input is in `Ans`.  
Output is in `Ans` and is automatically printed out when the program completes.
**Explanation:**  
(TI-BASIC doesn't have comments, so just assume that `;` makes a comment)
```
:2Ans=sum(seq(Ans/Xnot(remainder(Ans,X)),X,1,Ans    ;Full program
 2Ans                                               ;double the input
          seq(                                      ;generate a list
                                         X,          ;using the variable X,
                                           1,        ;starting at 1,
                                             Ans     ;and ending at the input
                                                     ;with an implied increment of 1
              Ans/X                                 ;from the input divided by X
                   not(                ),           ;multiplied by the negated result of
                       remainder(Ans,X)              ;the input modulo X
                                                     ;(result: 0 or 1)
      sum(                                          ;sum up the elements in the list
     =                                              ;equal?
```
**Example:**
```
6
            6
prgmCDGF2
            1
7
            7
prgmCDGF2
            0
```
---
**Note:** The byte count of a program is evaluated using the value in **[MEM]**>**[2]**>**[7]** (36 bytes) then subtracting the length of the program's name, `CDGF2`, (5 bytes) and an extra 8 bytes used for storing the program:
36 - 5 - 8 = 23 bytes
[Answer]
# [Java (JDK)](http://jdk.java.net/), 54 bytes
```
n->{int s=0,d=0;for(;++d<n;)s+=n%d<1?d:0;return s==n;}
```
[Try it online!](https://tio.run/##PY/BboMwDIbvfQqrEhKsLg3tQLQp23mHSZN6nHZISajStQElptJU8ewsQLeD7Vj@83/2WdzE8iy/e31taktw9n3ckr7EVWtK0rWJn/isvAjn4F1oA/cZQNMeL7oER4J8udVawtXPwgNZbU6fXyDsyUWjFODN0IdVUpeCFDTKVqokKKA3y5e7NgSuYCgLxqvahnyxkHvDI7coTCD3yavcMW4VtdZ4XWF41/PR1H/0GFKOnPeaQAAJJmtMNpjkuGaYMMZws0lT5hM@JBmuc3zeZpgn/vGYZrha5Wm@zbMtS7NJ2k2gYathywG1m4DRP@/w40hd47qluPGXUxXOA7mD4BiYOY5i/Ls4HrpwSFE0OXezIbr@Fw "Java (JDK) ‚Äì Try It Online")
Though for a strict number by number matching, the following will return the same values, but is only 40 bytes.
```
n->n==6|n==28|n==496|n==8128|n==33550336
```
[Try it online!](https://tio.run/##PY9Pa4NAEMXvfoohIGiZGP/UZU2w9x4KhRxLDxtdw1pdxR0DpfWz21WTHvYtj3nze0wtbmJfl1@zavtuIKitD0ZSTVCNuiDV6eDp5BSNMAbehNLw4wD046VRBRgSZL9bp0po7cw706D09eMTxHA1/hoFeNX0PshSFYIk9HKoZEGQw6z3LzrP2a@VmC/6nK2GR5tNkjQNk4TNpxWjNFkwSUPGbm9ogAijGKMEI45xiFEYhnjfS/EeYRhztGxcwI8pw8OBpzzjLAtTtkWnrajqBs@WrVXHrdD/7zt/G5Jt0I0U9PZWqrydWx7Bvbh6h2sYHzcGi/MW8f2NPDnLm@Y/ "Java (JDK) ‚Äì Try It Online")
[Answer]
# x86 Assembly, 45 43 Bytes.
```
6A 00 31 C9 31 D2 41 39  C1 7D 0B 50 F7 F9 58 85
D2 75 F1 51 EB EE 31 D2  59 01 CA 85 C9 75 F9 39
D0 75 05 31 C0 40 EB 02  31 C0 C3
```
**Explaination** (Intel Syntax):
```
PUSH $0          ; Terminator for later
XOR ECX, ECX        ; Clear ECX
.factor:
    XOR EDX, EDX    ; Clear EDX
    INC ECX
    CMP ECX, EAX    ; divisor >= input number?
    JGE .factordone ; if so, exit loop.
    PUSH EAX        ; backup EAX
    IDIV ECX        ; divide EDX:EAX by ECX, store result in EAX and remainder in EDX
    POP EAX         ; restore EAX
    TEST EDX, EDX   ; remainder == 0?
    JNZ .factor     ; if not, jump back to loop start
    PUSH ECX        ; push factor
    JMP .factor     ; jump back to loop start
.factordone:
XOR EDX, EDX        ; clear EDX
.sum:
    POP ECX         ; pop divisor
    ADD EDX, ECX    ; sum into EDX
    TEST ECX, ECX   ; divisor == 0?
    JNZ .sum        ; if not, loop.
CMP EAX, EDX        ; input number == sum?
JNE .noteq          ; if not, skip to .noteq
    XOR EAX, EAX    ; clear EAX
    INC EAX         ; increment EAX (sets to 1)
JMP .return         ; skip to .return
.noteq:
    XOR EAX, EAX    ; clear EAX
.return:
RETN
```
Input should be provided in `EAX`.  
Function sets `EAX` to `1` for perfect and to `0` for imperfect.
**EDIT**: Reduced Byte-Count by two by replacing `MOV EAX, $1` with `XOR EAX, EAX` and `INC EAX`
[Answer]
# Regex (Perl/PCRE+`(?^=)`[RME](https://github.com/Davidebyzero/RegexMathEngine)), ~~44~~ 41 bytes
```
((\2x+?|^x\B)(?^=\2+$))++$(?^!(\2x+)\3+$)
```
[Try it on replit.com](https://replit.com/@Davidebyzero/regex-Perfect-numbers-with-lookinto)
This was a port of my 48 byte .NET regex below, using lookinto instead of variable-length lookbehind. This makes it far faster, and able to scan all numbers from 0 to 9000 in about 7 seconds on my PC. It also enables somes golfs that aren't possible in the .NET version.
```
                   # No anchor needed, because \2 cannot be initially captured if
                   # matching is started anywhere besides the beginning.
# Sum as many divisors of N as we can (using the current position as the sum),
# without skipping any of them:
(
    (
        \2x+?      # \2 = the smallest number larger than the previous value of \2
                   # for which the following is true; add \2 to the running total
                   # sum of divisors.
    |
        ^x         # This must always be the first step. Add 1 to the sum of
                   # divisors, thus setting \2 = 1 so the next iteration can keep
                   # going.
        \B         # Exclude 1 as a divisor if N == 1. We don't have to do this for
                   # N > 1, because this loop will never be able to add N to the
                   # already summed divisors (as 1 will always be one of them).
    )
    (?^=\2+$)      # Assert that \2 is a divisor of N
)++                # Iterate the above at least once, with a possessive quantifier
                   # to lock in the match (i.e. prevent any iteration from being
                   # backtracked into).
$                  # Require that the sum equal N exactly. If this fails, the loop
                   # won't be able to find a match by backtracking, because
                   # everything inside the loop is done atomically.
# Assert that there are no more proper divisors of N that haven't already been summed:
(?^!               # Lookinto ‚Äì Assert that the following cannot match:
    (\2x+)         # \3 = any number greater than \2
    \3+$           # Assert \3 is a proper divisor of N
)
```
## Regex (Perl/PCRE+`(?^=)`[RME](https://github.com/Davidebyzero/RegexMathEngine)), 45 bytes
```
^(?=(x(?=(x*))(?^=(?(?=\2+$)(\3?+\2))))+$)\3$
```
[Try it on replit.com](https://replit.com/@Davidebyzero/regex-Perfect-numbers-with-lookinto-45-bytes)
This is a port of the largest-to-smallest 47 byte .NET regex below, using lookinto instead of variable-length lookbehind.
## Regex (Perl/PCRE+`(?^=)`[RME](https://github.com/Davidebyzero/RegexMathEngine)), 47 bytes
```
^(?=((?^0=(x*))(?^=(?(?=\2+$)(\3?+\2)))x)+$)\3$
```
[Try it on replit.com](https://replit.com/@Davidebyzero/regex-Perfect-numbers-with-lookinto-47-bytes)
This is a port of the smallest-to-largest 47 byte .NET regex below, using lookinto instead of variable-length lookbehind. This one is less conducive to being ported, and I had to use `(?^0=)`, lookinto accessing the in-progress current match. I've not decided how to finalize the current behavior of this, so it's likely this version will not work with a future version of lookinto.
# Regex (.NET), 47 bytes
```
^(?=((?<=(?=(?(\3+$)((?>\2?)\3)))(^x*))x)+$)\2$
```
[Try it online!](https://tio.run/##ZVBNT@MwEL3zK0yFVA9NIifsAWHcrhTtAQm0K4q0BwqSNx2KJdeJbKdrGvjtxU1aLvhijd8bv4/KpVVtcWfkGl0jKyTzN@dx3bVOmRUpRVkbV2vkw/yAwWf3uGq1tL9CY9E5FQm80tI5su6cl15VZFOrJbmTyhAK3UZa4sTP0e6ZzgSls2uxv2d0cTE5gzhPF8UMFhcAQJ/DOUCA@L4oznYjvl@1wuB/EjUxUJfN23/O22iF5onLbtGs/GtaQNLjvxu/d5OV9bpRGpfABy7R/KW2VBlPjGCcalHGEHJ5qwxSgFNhWq25ETl06oWaKYMy@2uVx4HQ22iEzuaNVp6O0zHw/V8qQX4SF5qDj2nx/n4agezBvv2R1iFtHtlTUreRCt@h41qaDxyEoywd3ZiN1LFDK80Kr0jHPkaJBo7aYd9n6EuZD02MwzhR8BVxGyOqa4FcTSZJmIgIQ3Rpsxt3J331SgP0Obffcm5Fzr8s9Jrh4BH4R392LM0ZYyeXecHSy/wH@wQ "C# (.NET Core) ‚Äì Try It Online")
```
^(?=(x(?=(x*$)(?<=(?(^\2+)(\2(?>\3?))))))+$)\3$
```
[Try it online!](https://tio.run/##ZZBfa9swFMXf@ynUEIju/AfZ3UOZqnhg9lBo2VgKe1hW0JzbVKDIRpIzN24/e6bIbV@qB4E45@r@zmlc1rQWj0bu0HWyQbJ6ch53Y@@U2ZJa1K1xrUY@ve9w8PlP3PZa2m9DZ9E5FQy80dI5shudl141ZN@qDbmVyhAK415a4sTX2fGeVoIO8fo0B1pdCVrR@3WZAF2XtFquLyqIJ5nD@mJ@nPHTqBUG/5GwEwfq8lX/13kbUGiRuvwGzdY/ZiWkUf/e@RNNXre7TmncAJ@8RPOH1lJlPDGCcapFHULIzY0ySAHOhem15kYUMKoHapYM6vyXVR4nQ8TohM5XnVaeLrIF8NNfKkV@Fga6V45l@fx8HoT8zj79kNYh7X6zP2nbByt8lN7GsmLyILytpbNrs5c6dGil2eIXMrKXWaqBo3YY@xxiKaupicWwSBW8RzyEiOpKIFdJkg6JCDIESptfu1vpm0c6QMx5@JDzIAr@jhB3Dq@MwF/iObKsYIydXRYlyy6Lz@w/ "C# (.NET Core) ‚Äì Try It Online")
This is based on [my 44 byte abundant numbers regex](https://codegolf.stackexchange.com/questions/110708/an-abundance-of-integers/219934#219934), with is in turn based on [Martin Ender's 45 byte abundant numbers regex](https://codegolf.stackexchange.com/questions/110708/an-abundance-of-integers/110732#110732). It was trivial to adapt to matching perfect numbers; just two small changes were needed, with a third change made for aesthetic purposes.
```
# For the purpose of these comments, the input number will be referred to as N.
^(?=                  # Attempt to add up all the divisors of N.
  (x                  # Cycle through all positive values of tail that are less than N,
                      # testing each one to see if it is a divisor of N. Start at N-1.
    (?=               # Do the below operations in a lookahead, so that upon popping back
                      # out of it our position will remaing the same as it is here.
      (x*$)           # \2 = tail, a potential divisor; go to end to that the following
                      # lookbehind can operate on N as a whole.
      (?<=            # Switch to right-to-left evaluation so that we can operate both
                      # on N and the potential divisor \2. This requires variable-length
                      # lookbehind, a .NET feature. Please read these comments in the
                      # order indicated, from [Step 1] to [Step 4].
        (?(^\2+)      # [Step 1] If \2 is a divisor of N, then...
          (           # [Step 2] Add it to \3, the running total sum of divisors:
                      #          \3 = \3 + \2
            \2        # [Step 4] Iff we run out of space here, i.e. iff the sum would
                      #          exceed N at this point, the match will fail, and the
                      #          summing of divisors will be halted. It can't backtrack,
                      #          because everything in the loop is done atomically.
            (?>\3?)   # [Step 3] Since \3 is a nested backref, it will fail to match on
                      #          the first iteration. The "?" accounts for this, making
                      #          it add zero to itself on the first iteration. This must
                      #          be done before adding \2, to ensure there is enough room
                      #          for the "?" not to cause the match to become zero-length
                      #          even if \3 has a value.
          )
        )
      )
    )
  )+                  # Using "+" instead of "*" here is an aesthetic choice, to make it
                      # clear we don't want to match zero. It doesn't actually make a
                      # difference (besides making the regex ever so slightly more
                      # efficient) because \3 would be unset anyway for N=0.
  $                   # We can only reach this point if all proper divisors of N, all the
                      # way down to \2 = 1, been successfully summed into \3.
)
\3$                   # Require the sum of divisors to be exactly equal to N.
```
# Regex (.NET), 48 bytes
```
((?=.*(\1x+$)(?<=^\2+))\2|^x\B)+$(?<!^\3+(x+\2))
```
[Try it online!](https://tio.run/##ZZDNbtswEITveQraCGBu9QNK7SEow6So0EOABC3qAD1UNcDKG4cATQkk5TKW8@wuLSW5hDdyZrnfTOOyprV4NHKLrpMNkuWT87gdeqfMhlSiao1rNfLpfo/B5z9x02tpv4XOonMqGnijpXNkOzgvvWrIrlVrcieVIRSGnbTEiS/zI6XXIv9A6yIk50CvL8WqLhOAujysQv0VkvP4NlvVHxMakroEOM75adYKg/9IXIqBunzZ/3XeRhZapC6/RbPxj1kJ6ah/7/wJJ6/abac0roFPXqL5Q2upMp4YwTjVooop5PpWGaQAM2F6rbkRBQzqgZorBlX@yyqPk2HE6ITOl51Wni6yBfDTXypFfhYHuheOq/JwmEUhv7dPP6R1SLvf7E/a9tEK76XXsayYPAiva@n8xuykjiVaaTb4mQzseZ5q4KgdjoWGsZTl1MQiLFIFbxH3MaK6FMhVkqQhEVGGSGnzG3cnffNIA4w59@9y7kXB3xDGneGFEfjzeI4sKxhjZxdFybKL4hP7Dw "C# (.NET Core) ‚Äì Try It Online")
This is based on [my 43 byte abundant numbers regex](https://codegolf.stackexchange.com/questions/110708/an-abundance-of-integers/219934#219934). It was interesting and somewhat tricky to adapt into a fully golfed perfect numbers regex.
```
                   # No anchor needed, because \1 cannot be initially captured if
                   # matching is started anywhere besides the beginning.
# Sum as many divisors of N as we can (using the current position as the sum),
# without skipping any of them:
(
    (?=            # Atomic lookahead:
        .*(\1x+$)  # \2 = the smallest number larger than the previous value of \1
                   # (which is identical to the previous value of \2) for which the
                   # following is true. We can avoid using "x+?" because the ".*"
                   # before this implicitly forces values to be tested in increasing
                   # order from the smallest.
        (?<=^\2+)  # Assert that \2 is a divisor of N
    )
    \2             # Add \2 to the running total sum of divisors
|
    ^x             # This must always be the first step. Add 1 to the sum of divisors,
                   # thus setting \1 = 1 so the next iteration can keep going
    \B             # Exclude 1 as a divisor if N == 1. We don't have to do this for
                   # N > 1, because this loop will never be able to add N to the
                   # already summed divisors (as 1 will always be one of them).
)+$                # Require that the sum equal N exactly. If this fails, the loop
                   # won't be able to find a match by backtracking, because everything
                   # inside the loop is done atomically.
# Assert that there are no more proper divisors of N that haven't already been summed:
(?<!               # Assert that the following, evaluated right-to-left, cannot match:
    ^\3+           # [Step 2] is a proper divisor of N
    (x+\2)         # [Step 1] Any value of \3 > \2
)
```
# Regex (Perl / PCRE2 v10.35+), ~~64~~ ~~60~~ 57 bytes
This is a port of the 41 byte regex, emulating variable-length lookbehind using a recursive subroutine call.
```
(?=((\2x+?|^x\B)((?<=(?=^\2+$|(?3)).)))++$)(?!(\2x+)\4+$)
```
[Try it online!](https://tio.run/##RY5RS8MwFIXf/RVxhPVe0rqkrjBMs3QyX33yzW5lygqBuNWkQqWrf73GMvDlcr9zDvfc5uhsNn58E@ok6e35/WAJXciAKt9uXjbrgdRnB9QrLvO1xJ4UVvnGmhaiJIr915tvg13FiYgFHj9n5Wmm/1UedHygFUpiavDh@sEVNk@xL@yr2Kkw@U5eO8wVqcnVZIeNMexNTQCiLiIdCSFEon7IgroF9tTP540zp/avVoYnhZyQUCOHYaiqp@dtVY2gFUCZdkxf9l35iAA6V0HclymjF9D3iHeIyBhF0LdTEstloHHkSZbxm5VIebISS/4L "Perl 5 ‚Äì Try It Online") - Perl  
[Attempt This Online!](https://ato.pxeger.com/run?1=fVHNbtQwEBbXfYrBspQZkuwmSyst8kaRECBVQhyAW9NaaXC6hqwTOV5ppbZPwqUS6rlPwUPA0zDZ7QUOHDyen--bbzz-_mPYDPe_n_1cl-yA9FCAWAiYw-DNtfZm6OrGYLSYvyi13tRd0E2_HWxnfIUVqerjYowSiPi0nNTXZgK4YFwYUet3Z-_fak0J5MQtubGaWWf1aAKKofFmflU334Jnozu7tUEkINJckIK_Yd40Oz_a3v0f9vVYyrgya3uP0haZkl3R8lgjfvr85uwDKboB26LszsfgO-PYozS_KApROUEMHndXXOF0kiVpThPf7Ieu_2JQpCJhuGJ-0-9cmLjrJZPOuQHb7ELNAA7K7imWbl0c6uzFMbE04GG12zo0G5Q-YbFpz6YOGO2jRDoigptpREum2fTTXAr4KbmCKQbp1B3L3P3zH0jqYRfadPXrFZYFYrXcx-Xt5b56TYjluuDkZbWM5S2WL4nmrBLHkrB8fkBSdcLRscH90_WYpaen2WyVL7N0lZ9kx_Qf "PHP - Attempt This Online") - PCRE2 v10.40+
```
                   # No anchor needed, because \2 cannot be initially captured if
                   # matching is started anywhere besides the beginning.
(?=
    # Sum as many divisors of N as we can (using the current position as the sum),
    # without skipping any of them:
    (
        (
            \2x+?      # \2 = the smallest number larger than the previous value of \2
                       # for which the following is true; add \2 to the running total
                       # sum of divisors.
        |
            ^x         # This must always be the first step. Add 1 to the sum of
                       # divisors, thus setting \2 = 1 so the next iteration can keep
                       # going.
            \B         # Exclude 1 as a divisor if N == 1. We don't have to do this for
                       # N > 1, because this loop will never be able to add N to the
                       # already summed divisors (as 1 will always be one of them).
        )
        ((?<=          # Define subroutine (?3); lookbehind
            (?=        # Circumvent the constant-width limitation of lookbehinds
                       # in PCRE by using a lookahead inside the lookbehind
                ^\2+$  # This is the payload of the emulated variable-length
                       # lookbehind: Assert that \2 is a divisor of N
            |
                (?3)   # Recursive call - this is the only alternative that can
                       # match until we reach the beginning of the string
            )
            .          # Go back one character at a time, trying the above
                       # lookahead for a match each time
        ))    
    )++                # Iterate the above at least once, with a possessive quantifier
                       # to lock in the match (i.e. prevent any iteration from being
                       # backtracked into).
    $                  # Require that the sum equal N exactly. If this fails, the loop
                       # won't be able to find a match by backtracking, because
                       # everything inside the loop is done atomically.
)
# Assert that there are no more proper divisors of N that haven't already been summed:
(?!                # Assert that the following cannot match:
    (\2x+)         # \4 = any number greater than \2
    \4+$           # Assert \4 is a proper divisor of N
)
```
It isn't practical to directly port the 47 byte regex to PCRE, because it changes the value of a capture group inside the lookbehind, and upon the return of any subroutine in PCRE, all capture groups are reset to the values they had upon entering the subroutine. It is possible, however, and I did this for the corresponding [Abundant numbers regex](https://codegolf.stackexchange.com/a/219934/17216) by changing the main loop from iteration into recursion.
# Regex (ECMAScript), 53 bytes ‚Äì Even perfect numbers
If it is ever proved that there are no odd perfect numbers, the following would be a robust answer, but for now it is noncompeting, as it only matches even perfect numbers. It was written by [Grimmy](https://codegolf.stackexchange.com/users/6484/grimmy) on [2019-03-15](https://chat.stackexchange.com/transcript/message/49504867#49504867).
```
^(?=(x(x*?))(\1\1)+$)((x*)(?=\5$))+(?!(xx+)\6+$)\1\2$
```
[Try it online!](https://tio.run/##Tc@9bsIwFAXgvU8BEaL3kiY4qEUI12TqwMLQjk0rWWAct8axbAMpP8@emqFSlytdfUc6Ol/8wP3aKRsyb9VGuF1jvsVP55gRx96rkC@tBTixxXjUfULJoIV2VCJCVVQFpgOE@GOE6mmAmELZh7ZNsZpGipHJoBuNT5iH5i04ZSRg7rVaC5g@ZI@I1DNCj7XSAkAzJ/hGKyMAsc/MXms8S6Zzb7UKcJ/dI1VbAMNkroWRocbF5HJRfsVXoJjlzoulCSDfyQfiH4j/YBZFWcxvjKF2zTFZmgPXatNz3Egx7yWpptvGAVXPTFCVphgLkzbJnbCCB1CY73hY1@AQz344tHFSgNuKgtp98MHFCL1eO5IVhJC7WTzZbELILw "JavaScript (SpiderMonkey) ‚Äì Try It Online")
This uses the fact that every [even perfect number](https://en.m.wikipedia.org/wiki/Perfect_number#Even_perfect_numbers) is of the form \$2^{n-1} (2^n-1)\$ where \$2^n-1\$ is prime. For \$2^n-1\$ to be prime, it is necessary that \$n\$ itself be prime, so the regex does not need to do a \$log\_2\$ test on \$2^n\$ to verify \$n\$ is prime. (I have used \$n\$ here instead of \$p\$ to make that clear.)
```
^                     # N = tail = input
(?=(x(x*?))(\1\1)+$)  # Assert that the largest odd divisor of N is >= 3 (due to
                      # having a "+" here instead of "*"; this is not necessary, but
                      # speeds up the regex's non-match when N is a a power of 2);
                      # \1 = N / {largest odd divisor of N}
                      #    == {largest power of 2 divisor of N}; \2 = \1 - 1
((x*)(?=\5$))+        # tail = N / {largest power of 2 divisor of N}
                      #      == {largest odd divisor of N}
(?!(xx+)\6+$)         # Assert tail is prime
\1\2$                 # Assert tail == \1*2 - 1; if this fails to match, it will
                      # backtrack into the "((x*)(?=\5$))+" loop (effectively
                      # multiplying by 2 repeatedly), but this will always fail
                      # to match because every subsequent match attempt will be
                      # an even number, and "\1\2$" can only be odd.
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 41 bytes
```
f(n,i,s){for(i=s=n;--i;s-=n%i?0:i);n=!s;}
```
[Try it online!](https://tio.run/##VYzNboMwEAbv@xTbRES2BJUNxTJxaR@k7YHwE1YiprKNcoh4dmqqXnpZ7Yw@TZtd23bbBmZTSj1/DLNjVPvamiwj47PaJvQuzsSNrZ@8Wbcj2XZauh5ffehofh7f4J@a6LI7IBvw1pBl/AG4g11uBrAdG4eXZfiQ6ivifaSpZ9c@eBYlx9MJWRxijU2Yp1/H9wB@u9gY2CHpzph0n/aQ7sEUh33OeUytgK4Pi7MoDKybBJmDLEBqyAVIIQQURVmKeEBBruGlUqBlfP50pFJXWlWiVD8 "C (gcc) ‚Äì Try It Online")
```
1: 0
12: 0
13: 0
18: 0
20: 0
1000: 0
33550335: 0
6: 1
28: 1
496: 1
8128: 1
33550336: 1
-65536: 0 <---- Unable to represent final test case with four bytes, fails
```
Let me know if that failure for the final case is an issue.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 5 [bytes](https://github.com/barbuz/Husk/wiki/Codepage)
```
=¬πŒ£h·∏ä
```
Yields `1` for a perfect argument and `0` otherwise.
**[Try it online!](https://tio.run/##yygtzv7/3/bQznOLMx7u6Pr//78ZAA "Husk ‚Äì Try It Online")**
### How?
```
=¬πŒ£h·∏ä - Function: integer, n   e.g. 24
    ·∏ä - divisors                    [1,2,3,4,6,8,12,24]
   h  - initial items               [1,2,3,4,6,8,12]
  Œ£   - sum                         36
 ¬π    - first argument              24
=     - equal?                      0
```
[Answer]
# [Actually](https://github.com/Mego/Seriously), 5 bytes
```
;√∑Œ£¬Ω=
```
Full program taking input from STDIN which prints `1` for perfect numbers and `0` otherwise.
**[Try it online!](https://tio.run/##S0wuKU3Myan8/9/68PZziw/ttf3/38gCAA "Actually ‚Äì Try It Online")**
### How?
```
;√∑Œ£¬Ω= - full program, implicitly place input, n, onto the stack
;     - duplicate top of stack
 √∑    - divisors (including n)
  Œ£   - sum
   ¬Ω  - halve
    = - equal?
```
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), 45 bytes
```
: f 0 over 1 ?do over i mod 0= i * - loop = ;
```
[Try it online!](https://tio.run/##LYzLCsIwEEX38xWHLoWUPKxUS/VjGquCkhCqvx8z6ObeM5fDrKlsd3NbtWo9sWJJn2vBcYnphw9eKWLnBjsMz5QyM1OzM/GdGekL0HdgznTth9dlKUyIHJolfiTL/thYRqcHEsIw2BB0Woq4Vs5rBA3VvVWyVusvD@T6BQ "Forth (gforth) ‚Äì Try It Online")
### Explanation
Loops over every number from 1 to n-1, summing all values that divide n perfectly. Returns true if sum equals n
### Code Explanation
```
: f                \ start word definition
  0 over 1         \ create a value to hold the sum and setup the bounds of the loop
  ?do              \ start a counted loop from 1 to n. (?do skips if start = end)
    over           \ copy n to the top of the stack
    i mod 0=       \ check if i divides n perfectly
    i * -          \ if so, use the fact that -1 = true in forth to add i to the sum
  loop             \ end the counted loop
  =                \ check if the sum and n are equal
;                  \ end the word definition
   
```
[Answer]
# [Kotlin](https://kotlinlang.org), 38 bytes
```
{i->(1..i-1).filter{i%it==0}.sum()==i}
```
Expanded:
```
{ i -> (1..i - 1).filter { i % it == 0 }.sum() == i }
```
Explanation:
```
  {i->                      start lambda with parameter i
    (2..i-1)                create a range from 2 until i - 1 (potential divisors)
      .filter{i%it==0}      it's a divisor if remainder = 0; filter divisors
        .sum()              add all divisors
          ==i                compare to the original number
             }               end lambda
```
[Try it online!](https://tio.run/##HY2xCsIwEED3fsV1EO6GBLs4COngJvgTQVM4TC/SXl1Cvj0mvvnx3jtpZKlfH2E55HkFvIsSmBluKcXgBRzUzGbGyVo2E9mFo4Yt84nVuXOx@7EiOceltgCsngUJ8gCNXtWwa2tswb8eLAFpHK2mNkH6O5@NRaNgv2OXiYZSLz8)
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), ~~5~~ 4 bytes
```
‚îÄ‚ï°Œ£=
```
[Try it online!](https://tio.run/##y00syUjPz0n7///RlIZHUxeeW2z7/78hlxGXMZcJlymXGZeROZeRxX8A "MathGolf ‚Äì Try It Online")
## Explanation
```
‚îÄ       get divisors (includes the number itself)
 ‚ï°      discard from right of list (removes the number itself)
  Œ£     sum(list)
   =    pop(a, b), push(a==b)
```
Since MathGolf returns divisors rather than proper divisors, the solution is 1 byte longer than it would have been in that case. 
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 ~~13~~ bytes
```
qsf!%QTSt
```
[Try it online!](https://tio.run/##K6gsyfj/v7A4TVE1MCS45P9/QyMA "Pyth ‚Äì Try It Online")
Thank you to the commentors for the golf help 
Finds all the factors of the input, sums them, and compares that to the original input.
[Answer]
# [VDM-SL](https://raw.githubusercontent.com/overturetool/documentation/master/documentation/VDM10LangMan/VDM10_lang_man.pdf), 101 bytes
```
f(i)==s([x|x in set {1,...,i-1}&i mod x=0])=i;s:seq of nat+>nat
s(x)==if x=[]then 0 else hd x+s(tl x) 
```
Summing in VDM is not built in, so I need to define a function to do this across the sequences, this ends up taking up the majority of bytes
A full program to run might look like this:
```
functions 
f:nat+>bool
f(i)==s([x|x in set {1,...,i-1}&i mod x=0])=i;s:seq of nat+>nat
s(x)==if x=[]then 0 else hd x+s(tl x)
```
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 4 bytes
```
dŒ£‚Åª=
```
[Try it online!](https://tio.run/##S0/MTPz/P@Xc4keNu23//zeyAAA "Gaia ‚Äì Try It Online")
1 for perfect, 0 for imperfect.
```
d	| implicit input, n, push divisors
 Œ£	| take the sum
  ‚Åª	| subtract n
   =	| equal to n?
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal),  ~~3+1~~ 3 bytes
```
‚àÜK=
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%E2%88%86K%3D&inputs=1&header=&footer=)
*-1 byte thanks to @Deadcode for telling me to not be an idiot and remember that I added a sum of proper divisors built-in. I actually forgot that I did*
This is: does the sum of the proper divisors of the input (`‚àÜK`) equal the input itself (`=`).
[Answer]
# Qbasic, ~~53~~ 47 bytes
Thank you @Deadcode, -6 bytes
```
INPUT n
FOR i=1TO n-1
s=s-i*(n\i=n/i)
NEXT
?n=s
```
Literally quite Basic... Prints `-1` for perfect numbers, `0` otherwise.
[REPL](https://repl.it/@pimsteenbergh/FlickeringJadedSymbol)
[Answer]
# Machine Language (x86 32-bit), ~~24~~ 23 bytes
This is a macro that takes an unsigned integer in EAX as input (N), and outputs the result in the Zero Flag (set=perfect, clear=imperfect). It also outputs a result in the Carry Flag (set=abundant, clear=non-abundant). As such, it's actually an answer for both this question and [An abundance of integers!](https://codegolf.stackexchange.com/questions/110708/an-abundance-of-integers), requiring no modification.
It's based on [640KB's abundant numbers answer](https://codegolf.stackexchange.com/questions/110708/an-abundance-of-integers/179016#179016), with the two additional optimizations from [l4m2's answer](https://codegolf.stackexchange.com/questions/110708/an-abundance-of-integers/179303#179303), where the divisors are subtracted from N instead of added to it (thus simultaneously setting the flags for the return value). An input of 1 is correctly handled, costing ~~3~~ 2 bytes.
```
89 C1 89 C3 9E EB 0E 31 D2 50 F7 F1 58 85 D2 75 04 29 CB 72 02 E2 F0
```
[Try it online!](https://tio.run/##jVZNb@M4DD1Hv4KYSxpMOusk7e42RQ/ZbAvsYjGXuRQzKAzZomMNbMmw5DSdP9@lbPlrEkziQxtJ5CP5SJHixmAeZW/XCTf5e6LLnFt4/O8J8IBxZXmUIawYC43lpV2zSYYcAI2cwzdpwgLLBGP70u4Lt49KhKOzXO8BojeL8E1VeYTlx@XLHKYwZSkeQlHlRZhpXTh0LUzkFXg6B56xiUlLWmRzuGETrkRzEByeaCXc6kBQQTBlkzgvGsHpHa2@RwhAXhkbGrkLlYwolNDkPMtaTSe6mV5fkfzHxYydFl63wOkQONe/wE3HuCdl1z7KV12KlhYihR/8PgqKa@Vt13wTuc44kAEhQlPwGE9g1NQGh02wYROp4hqIdQqtVYwJvVFodyLaWbQLR@qNA7BAYH8Gp/0YZa/PpdCKDA2hFqyvh/U7@K/3hIT83j3EungDqYrKegdpYTU8bp/ZWDG6UPGvXtHwNIGfvnsSg5gb/EnXwGJO9WPh69NDAK7wtvSjg/ru@Ii1snXwLRQe4qwSCLqUO6l41qJxAxyE3EujS5bw2PqCb9EOuvQppz99RFSRJTz@/QxXqdylTZ7pitZIgq7ZrAMoKpMO2PAAhu8HvrRanRJt1AkYKzVizuz6cfMMv42oL1ysR3ZKNFaXeGzB0sFxXDIhjZxLJYiaBwjmIK3XNYB7VNlbz7P6cYJnQlDazusDqSqEugK7NFdRWx9xb/VLFdmSqG/zAEmpc1ce92BTSreReZVZrlBXZuDAqY9Sk3K1I29tilBWSkm1A6utaymuVAza5izJ@M64nJ3Bq3HQVqWCPc8q/NQTELtM0ZUayf@TuHKkCnWKpspBJ21cxsVfR4qiixFSbs64QLWLKEhHV@XoLswhR15HSGkionhUKcGVnZ8BdES8IihCJW4In9Sdu3UilX51mz5ml4AzaFRjlB53WTteP7GuMPqrVKN3V4zVzegXoD3l6zMOXP37dQZUrtQPFvTPt7OzSp9J66FpIg8g80vVtrWtbWOrZfy8se2s0XLGlFbXF2tuWntNr/P@CkxkLPESy5tZ66/rZZ4k50KH8T5@GLgRUd/unpRJ28bY6EGh8DWTCq8XL8PxRcPKWDEaXwETGEsar@17YtRX2aRpeBH9OsTprplN9UH/HnAPCWpm7hXSjM/4WLrparyZPz6IoeFu8ko2nOY11GDouTl6yewlWnzXZR1VjrzGiPOgGc5OcRnQ598oPdVDidXq9jZYLZ0QJ6GCGgOGy6HxTsKfrY/Vb0/YaNmmYGqKh@N/GI0fiSAi@HCzvLu5@/2P5d3tB@az7Pbp/fL@Pw "Assembly (fasm, x64, Linux) ‚Äì Try It Online")
```
89 C1              mov  ecx, eax     ; copy input number into ECX
89 C3              mov  ebx, eax     ; copy input number into EBX
9E                 sahf              ; in case input number is 1, let ZF=0 and CF=0
EB 0E              jmp  cont_loop    ; exclude original number as a divisor
       fact_loop:                    
31 D2              xor  edx, edx     ; clear EDX (high word for dividend)
50                 push eax          ; save original dividend
F7 F1              div  ecx          ; divide EDX:EAX / ECX
58                 pop  eax          ; restore dividend
85 D2              test edx, edx     ; if remainder = 0, it divides evenly
75 04              jnz  cont_loop    ; if not, continue loop
29 CB              sub  ebx, ecx     ; Subtract divisor from EBX; this simultaneously
                                     ; changes the running total, and sets the flags for
                                     ; the return value.
72 02              jc   done         ; If CF=1, the sum of divisors subtracted from EBX has
                                     ; exceeded our input number, meaning it is abundant,
                                     ; and we need to exit the loop now to return this
                                     ; result in the flags.
       cont_loop:                    
E2 F0              loop fact_loop    
       done:                         ; return value:
                                     ; (JZ)  = ZF=1 = perfect
                                     ; (JNZ) = ZF=0 = imperfect
                                     ; (JC)  = CF=1 = abundant
                                     ; (JNC) = CF=0 = non-abundant
                                     ; (JA)  = CF=0 and ZF=0 = deficient
                                     ; (JNA) = CF=1 or  ZF=1 = non-deficient
```
[Answer]
# [Machine Language (x86 32-bit)](https://flatassembler.net/), 21 bytes
```
is_perfect:
        mov  ecx, esi       ; copy input number into ECX
	inc  esi
        mov  ebx, esi       ; copy input number + 1 into EBX
fact_loop:
        xor  edx, edx       ; clear EDX (high word for dividend)
        mov  eax, esi
        div  ecx            ; divide (n+1) / ECX
        dec  edx            ; if remainder = 1, n/ECX is zero and ECX is not 1
	                    ; In case EAX = 2^32-1, this doesn't work as intended
	                    ; (get edx=0 for all ECXs)
                            ; According to test 2^(2^n)-1 up to 2^128-1 are all
	                    ; deficient so it happens to be correct
        jnz  cont_loop      ; if not, continue loop
        sub  ebx, eax       ; Subtract divisor from EBX; this simultaneously
                            ; changes the running total, and sets the flags for
                            ; the return value.
        jc   done           ; If CF=1, the sum of divisors subtracted from EBX has
                            ; exceeded our input number, meaning it is abundant,
                            ; and we need to exit the loop now to return this
                            ; result in the flags.
cont_loop:
        loop fact_loop
	dec  ebx            ; Subtract the 1 added into esi for ZF
done:                       ; return value:
                            ; (JZ)  = ZF=1 = perfect
                            ; (JNZ) = ZF=0 = imperfect
end_is_perfect:
```
[Try it online!](https://tio.run/##hVZNb@M2ED1bv2KwFzuIvSs5abtxkIO7TYAtil56CRIkBiWOLG4lUhCpRN4/nw4p6itwYx1sk@I8znvzZaY1FnF@WKVMF2@pqgpm4PavO8AGk9qwOEe4CIKdNqwym2CWIwNALZbwKPSuxCrFxDx1@9zuo@S7ybtCvQDEB4PwKOsixup8/bSEOcyDDJsdr4tylytVWnTFdewNWLYElgcznVW0yJdwGcyY5O2LsLmjFberhqDCcB7MkqJsD86vaPUjRgDySpudFvudFDFR2emC5XlnaY9u56sFnT@PzoLjhzcdcDYGLtQHuNkU9@jZjWf5qireyUKisMbvIydeF/5upzeJay8HuoDznS5ZgkcwnLRhsw23wUzIxAEFvUF3KyaE3hp0OzHtRN3CinppAQwQ2NfwuB@T6A2x5ErSRR2UNYnehnzYBOCfwRM65PeuIVHlAYQsa@MdpIVRcPvtviOkxTuI@CTEOUQe5vf7IGWJ8QnX4TSq8pLTx4BDGVHB7R/3sMjEPmt1phIBLl4EpzQ/e@cIax3pd@mcYwij59pbw0JScsAXx6w3wDZiUwORQoUFE5ITlRuIKHRfyAqEhp9YKbBV4ddSGRtFOPJcw3cJCdMIt9t7glk/X6xXhGUysuMKtZwbS/FfYNqKRfyQ/x/UYo/GOnoTOkEooa0HehDkuNk2SUhDIfdAsTCoDXmxWD/Ls1UEdWk318/R@iutWIXgSuo4EMdUJAIpP7UCYSBjZYlSWwQqT7qkolTrnfkhfwJtyjbsI1lJrqV7IWSN4NK4s9F13KUWG1Linzo2FeWPC6Im5mmlCptV162OWhR1bphEVev8cEKNJGNyj@R0hlDVUra6GNuXbEg1mvZdmrO9tjqfwHM4aOpKwgvLa/w8CJDY5KK6nOZDCt/ublwKIPEtQKUdL235O6bIe46ksj7hAjYJIuUNqLqalOASCmSOIUWLhGJxLTmTZnkC0ArxiiAJ1QYXGzK37rpASvVqNz1nG4ATaBVqCg85Nuj6OegTY@gHDr3vE8Gsrcv4XV32yWDBItuWyUnXZmw3snXxcBe4bviBQ0O4NiecX/z5cAZUuA8UM/ry/fSk0d9k5YxC@hJFZzad0pu38WSnz1X0RNZpLRMjlCRWSUXjkfhZavHBNhlXVQPgjEa14f34IhyJr7mQOB4qtjuq2vhxP2m7k0FEE6dtnnHjpyq309qOed8jhT//SD9p5HFqFa6htNfYOer885eNp6p365wotEXeOiDGs3G0/HgwEu1egs1oQo0GZhTS4/83DIoHGctNrwFd4qgOt0STWwI/yIDH8OlyfXV59etv66tfPgWejN2Pwrf/AA "Assembly (fasm, x64, Linux) ‚Äì Try It Online")
# [Machine Language (x86 32-bit)](https://flatassembler.net/), 22 bytes edited from [here](https://codegolf.stackexchange.com/a/220380/) with also abundant? output
```
is_perfect:
        mov  ecx, esi       ; copy input number into ECX
        mov  ebx, esi       ; copy input number into EBX
fact_loop:
        xor  edx, edx       ; clear EDX (high word for dividend)
        lea  eax, [esi+1]
        div  ecx            ; divide (n+1) / ECX
        dec  edx            ; if remainder = 1, n/ECX is zero and ECX is not 1
	                    ; In case EAX = 2^32-1, this doesn't work as intended
	                    ; (get edx=0 for all ECXs)
                            ; According to test 2^(2^n)-1 up to 2^128-1 are all
	                    ; deficient so it happens to be correct
        jnz  cont_loop      ; if not, continue loop
        sub  ebx, eax       ; Subtract divisor from EBX; this simultaneously
                            ; changes the running total, and sets the flags for
                            ; the return value.
        jc   done           ; If CF=1, the sum of divisors subtracted from EBX has
                            ; exceeded our input number, meaning it is abundant,
                            ; and we need to exit the loop now to return this
                            ; result in the flags.
cont_loop:
        loop fact_loop
	test ebx, ebx       ; Not SUBed in last cycle
done:                       ; return value:
                            ; (JZ)  = ZF=1 = perfect
                            ; (JNZ) = ZF=0 = imperfect
                            ; (JC)  = CF=1 = abundant
                            ; (JNC) = CF=0 = non-abundant
                            ; (JA)  = CF=0 and ZF=0 = deficient
                            ; (JNA) = CF=1 or  ZF=1 = non-deficient
end_is_perfect:
```
[Try it online!](https://tio.run/##jVZNb@M2ED1bv2KwF9uIvSs5abtxkIM3TYAWxV4WBYINEoMSRxa3EimIVCLvn0@HFCVZhRtHhzj8mDczbx6HZFpjEef7Zcp08ZqqqmAGbv@6A2wwqQ2Lc4TzINhqwyqzDiY5MgDUYgEPQm9LrFJMzGM3z@08Sr4drRXqGSDeG4QHWRcxVmerxwVMYRpk2Gx5XZTbXKnSoiuuY2/AsgWwPJjorKJBvoCLYMIkbxfC5o5G3I4aggrDaTBJirLdOL2k0Y8YASgqbbZa7LZSxJTKVhcszztLu3UzXc5o/1k0D45vXnfA2SFwod7Azca4R/eufZYvquIdLUQKa/w8csrr3Pt2fBO51jmQA863umQJHsFw1IbNJtwEEyETBxT0Bp1XTAi9NehmYpqJuoEl9cICGCCwz@HxOEbVG2rJlSRHHZQ1iV4HPawD8N8QCW3yc1eQqHIPQpa18QHSwCi4vbn/j2H8TsMv90HKEuMl1mE0qvIk058BgzRQwe3v9zDLxC5rmaVDAVw8C07CnvcAreAtUQ8UxVn02K/QXpcXHHxXHgFmkiQBn0b5cGzrNDYQKVRYMCE5pXINERXsE1mB0PATKwX2LPixVMbWDo58V/CHhIRphNvNPcGsns5XS8IyGdlxhVpOjU3zH2DaEkY5Iv8/qNkOjQ30OnSkkIxtBHog5bjZJkmIRyF3QPUwqA1FMVs9yfkygrq0k6unaPWZRqxCcAfpOBDHVCQCSZVagTCQsbJEqS0CHUpyUpHA@mB@yJ9Ak7It/QGtRNfCLQhZIzjxdja6jjtpsUEW3@rYVKQhV0RNmaeVKqyyrloetSjq3DCJqtb5/gQbScbkDinoDKGqpWx5MbYb2ZJqNO1amrOdtjyfwHM4aOpKwjPLa/w4EJBYcdFpHOshhZu7aycBpHwLUGmXl7b5u0yR9zkSy/pECNgkiKQbUHU1OoILKJC5DKlaRBSLa8mZNIsTgJaIFwRJqLa42JC5DdcVUqoXO@lztgU4gVahpvJQYAOvH4NeGENPcOh9rwgmTqqtGOJBDF/psH37@wtFRoA5XRmQ7KlvBK7tvRHDUKH1iXhnf36fA53V71Qm@vGN86TRV7JyRiH9iOK9ZjfO103rqyvQaWc389bKOpNKLt9tuen8ha7MPt7@aJ/2vJl38doe7kmyIQwY4yfI@nXiesHAyYSeFYb3Vy1dURJfciHx8AKkth6o2vinyejCGF2adDu2LT9u/AuA25eFfZL4zi78/gf6l65nnnfaYm2jCdr4vLPDF4AP64y6e9ua2gDE4T1@MHz7Eqe0ewrW3fOAkjy43KOQPv/GGQgMMpabngNy4lIdvEQjL4G/foHH8OFidXlx@etvq8tfPgQ@GTsfha//Ag "Assembly (fasm, x64, Linux) ‚Äì Try It Online")
Bad luck in last round `sub` is not runned and a `test` is needed
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), ~~70~~ ~~67~~ 63 bytes
*-3 bytes thanks to [@Jo King](https://codegolf.stackexchange.com/users/76162/jo-king)*
*-4 bytes thanks to [@Steffan](https://codegolf.stackexchange.com/users/92689/steffan)*
```
$N:-bagof(M,(between(1,N,M),N mod M<1),L),sumlist(L,S),S=:=2*N.
```
[Try it online!](https://tio.run/##LYlBC0RAHEe/ioMys/1o/mPJ2qXccXFRcqBFCiNsbr661baX1@u9eVGD6sx1789TT32zrjrVsgSsbra9aSZGSJFwpNqo3lryIo6YY/2MQ79uLEbGkQV@IG@pdfrmWM2/XkRlGDKmR8gDeuaB4GjVMlYbM45ZM0PtmI/JQHH9knMUBJIgG@RBCpAQArbtOOICXEgP94cLjy75Z7fk1vkF "Prolog (SWI) ‚Äì Try It Online")
]