[Question]
  [
# Divinacci ([OEIS](https://oeis.org/A000458))
**Perform the Fibonacci sequence but instead of using:**
```
f(n) = f(n-1)+f(n-2)
```
**Use:**
```
f(n) = sum(divisors(f(n-1))) + sum(divisors(f(n-2)))
```
For an input of `n`, output the nth term, your program should only have 1 input.
---
**First 14 terms (0-indexed, you may 1-index; state which you used):**
```
0  | 0     # Initial               | []
1  | 1     # Initial               | [1] => 1
2  | 1     # [] + [1]              | [1] => 1
3  | 2     # [1] + [1]             | [1,2] => 3
4  | 4     # [1] + [1,2]           | [1,2,4] => 7
5  | 10    # [1,2] + [1,2,4]       | [1,2,5,10] => 18
6  | 25    # [1,2,4] + [1,2,5,10]  | [1,5,25] => 31
7  | 49    # [1,2,5,10] + [1,5,25] | [1,7,49] => 57
8  | 88    # [1,5,25] + [1,7,49]   | [1, 2, 4, 8, 11, 22, 44, 88] => 180
9  | 237   # [1,7,49] + [180]      | [1, 3, 79, 237] => 320
10 | 500   # [180] + [320]         | [1, 2, 4, 5, 10, 20, 25, 50, 100, 125, 250, 500] => 1092
11 | 1412  # [320] + [1092]        | [1, 2, 4, 353, 706, 1412] => 2478
12 | 3570  # [1092] + [2478]       | [1, 2, 3, 5, 6, 7, 10, 14, 15, 17, 21, 30, 34, 35, 42, 51, 70, 85, 102, 105, 119, 170, 210, 238, 255, 357, 510, 595, 714, 1190, 1785, 3570] => 10368
13 | 12846 # [2478] + [10368]      | [1, 2, 3, 6, 2141, 4282, 6423, 12846] => 25704
Etc...
```
*You may choose whether or not to include the leading 0. For those who do: the divisors of `0` are `[]` for the purpose of this challenge.*
It's [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") lowest byte-count wins...
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
XÎFDŠ‚ÑOO
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/4nCfm8vRBY8aZh2e6O///7@hMQA "05AB1E – Try It Online")
**Explanation**
```
XÎ          # initialize stack with 1,0,input
  F         # input times do
   D        # duplicate
    Š       # move down 2 places on the stack
     ‚      # pair the top 2 elements on the stack
      Ñ     # compute divisors of each
       OO   # sum twice
```
[Answer]
## Mathematica, ~~45~~ 40 bytes
```
If[#<3,1,Tr@Divisors@#0[#-i]~Sum~{i,2}]&
```
Mathematica's divisor related functions `Divisors`, `DivisorSum` and `DivisorSigma` are all undefined for **n = 0** (rightly so), so we start from `f(1) = f(2) = 1` and don't support input `0`.
Defining it as an operator instead of using an unnamed function seems to be two bytes longer:
```
±1=±2=1
±n_:=Sum[Tr@Divisors@±(n-i),{i,2}]
```
[Answer]
# [Perl 6](http://perl6.org/), 58 bytes
```
{my&d={sum grep $_%%*,1..$_};(0,1,{d($^a)+d $^b}...*)[$_]}
```
[Try it online!](https://tio.run/##BcFBCoAgEADAr@xhEy1Z8tJFekmkGGaXJDE6iPh2m0lnvpceC7AAa6@xML/W94tw5TMB2mEYpSJC2zSfpZLVczROTB7QHI2IRrGh3VvXEDhaQa8rEJ4MRs39Bw "Perl 6 – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 55 bytes
```
f n=sum[a|n>1,k<-f<$>[n-1,n-2],a<-[1..k],mod k a<1]+0^n
```
[Try it online!](https://tio.run/##FcpNCoAgEAbQq3wLd6k0QTvrImIwUFKYk/Sz6@5Gb/1WvtKy77VGyHA92fMrI@nkTHRq9GJIi@mCZmc8WZuCzseMBHYUmnaSmnkTDCjnJjcUMhdE/JX6UD8 "Haskell – Try It Online")
One-indexed.
[Answer]
# [Python 2](https://docs.python.org/2/), 76 bytes
```
f=lambda n:sum(a for k in[1,2][:n]for a in range(1,3**n-8)if f(n-k)%a<1)or n
```
[Try it online!](https://tio.run/##JcpBCoMwEAXQq8xGyEgEo1CK1JOIiyk6Nth8Q7SLnj61uH28@D1eG5qctX9LeE5C6PZPMEK6JVrJY3C2GYcO4x/kBEqCZTbOtmWJ6s5eSQ2qlQt5OD4TckweBwWJRu21a3tjzj8 "Python 2 – Try It Online")
Ridiculously slow.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~10~~ 9 bytes
```
ð,ÆDẎSð¡1
```
[Try it online!](https://tio.run/##y0rNyan8///wBp3DbS4Pd/UFH95waKHh//@mAA "Jelly – Try It Online")
Thanks to [Dennis](https://codegolf.stackexchange.com/users/12012/dennis) for -1.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~88~~ ~~83~~ 81 bytes
```
f=lambda n:+(n<3)or g(f(n-1))+g(f(n-2))
g=lambda n,i=1:n>=i and(n%i<1)*i+g(n,i+1)
```
[Try it online!](https://tio.run/##PYyxCsJAEAV7v2IbYZ8XizVdyOVHxOIk3rmgL@FI49efAcFuYIZZP9tzYd9ajq/0vs9JOATl2GOpUjQrzwaEH12AQ/l3nUcbOEWXxFl59NFw8j3dTTC0tTo3vWZ1SN5vLk6pieWh1pnhhvYF "Python 3 – Try It Online")
Excludes the `0`
[Answer]
# MATL, ~~16~~ 15 bytes
```
Oliq:",yZ\s]+]&
```
This solution uses 0-based indexing.
Try it at [MATL Online](https://matl.io/?code=Oliq%3A%22%2CyZ%5Cs%5D%2B%5D%26&inputs=9&version=20.1.1)
**Explanation**
```
O        % Push the number literal 0 to the stack
l        % Push the number literal 1 to the stack
i        % Explicitly grab the input (n)
q        % Subtract 1
:        % Create the array [1...(n - 1)]
"        % For each element in this array...
  ,      % Do the following twice
    y    % Copy the stack element that is 1-deep
    Z\   % Compute the divisors
    s    % Sum the divisors
  ]      % End of do-twice loop
  +      % Add these two numbers together
]        % End of for loop
&        % Display the top stack element
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~64~~ 60 bytes
```
d n=sum[a|a<-[1..n],mod n a<1]
f=0:scanl((.d).(+).d)1f
(!!)f
```
[Try it online!](https://tio.run/##DcixCoAgEADQva@4oEGpjqQt8kvE4cikSK/Q2vp3a3rwNsrHGkIpDljnJxp6ae6NQmTbxfNfoFnZyuthygtxEAKdRNHKH@WrpEVdS18i7QwarrTzDQ1EuiCBGRDVaMsH "Haskell – Try It Online")
[Answer]
# [PHP](https://php.net/), 97 bytes
```
for($f=[0,$y=1];++$i<$argn;$x=$y,$y=$r)for($f[]=$r=$v=$n=$x+$y;--$v;)$n%$v?:$r+=$v;echo$f[$argn];
```
[Try it online!](https://tio.run/##JYw9C8IwFEX3/oxyhYZYUNx8fXSQDi66uJVQRNKPJQkPKe3iX4@xbpdzDjeMIVZ1GENmRbx0YoOX9@SG4tN0t/vjemkUZXjK4Dg/5RR7LwV6bg97rHw0pDWmavOEhbH@MET9s9akzZgZjrForFSWmEnB7TDXZ4hOkuxr9KndTgzF@AU "PHP – Try It Online")
# [PHP](https://php.net/), 101 bytes
```
for($f=$d=[0,1];$i<$argn;$d[]=$r)for($f[]=$r=$v=$n=$d[$i]+$d[++$i];--$v;)$n%$v?:$r+=$v;echo$f[$argn];
```
[Try it online!](https://tio.run/##JYw9C8IwFEX3/oxyhZZYsLj5@uggHVx0cSuhiP1IliQ8JKN/PYY63QP33BtMSF0fTCgWES@TLMHLx7qt@g7T/fG8XYeaCrxkc1y255LS6qXCyph5PB1bTbDdXhPmUTOk/gs7MyLDZXeE1SqHUhmoaRCphjsg9heIyhotb@Pzar/SlNIP "PHP – Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 39 bytes
```
f(n)=if(n<3,1,sum(i=1,2,sigma(f(n-i))))
```
Based on [Martin Ender's Mathematica answer](https://codegolf.stackexchange.com/a/128040/9288).
[Try it online!](https://tio.run/##FYyxDcAgDARXsVIZyS4MbcguNCAXEAuS@YnzxRWn01uZys32rjhCVueZSGi9HTULRVraekH3rMG36z1xQAYhkERgU8fj4gC@HP@LRx8 "Pari/GP – Try It Online")
[Answer]
# R, 81 bytes
```
f=function(n,a=1,b=1,d=numbers::divisors)`if`(n-1,f(n-1,b,sum(d(a))+sum(d(b))),a)
```
1-indexed, and excludes the 0 at the start of the sequence. That zero gave me a lot of trouble to implement, because the builtin `numbers::divisors` doesnt handle it well.
The rest is a modified version of the standard recursive function that implements the fibonacci sequence.
```
> f(1)
[1] 1
> f(2)
[1] 1
> f(3)
[1] 2
> f(5)
[1] 10
> f(13)
[1] 12846
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 9 bytes
```
1{~"vKf∑…
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIxe35cInZLZuKIkeKApiIsIiIsIiJd)
Prints the sequence forever.
```
1         # Push 1
 {        # Forever...
  ~"      # Grab top two elements, without popping
    vK    # Get divisors of each
      f∑  # Deep sum
        … # Print that without popping
```
[Answer]
# [Julia](https://julialang.org), ~~47~~ 44 bytes
```
~n=(n.%(r=1:n).<1)'r
!N=N<3||~!(N-1)+~!(N-2)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700qzQnM3HBgqWlJWm6Fjd16vJsNfL0VDWKbA2t8jT1bAw11Yu4FP1s_WyMa2rqFDX8dA01tcG0kSZEz6aCosy8kpw8PQ09RQ1DK0NjTagEzFAA)
-3 bytes thanks to [Czylabson Asa](https://codegolf.stackexchange.com/users/90445/czylabson-asa). (I forgot [how `a'*b` worked](https://ato.pxeger.com/run?1=m700qzQnM3HBgqWlJWm6FjdVghRsFQytTLkcijPyyxWC1LWCoEwNAwU9baCAplYQRC1UC0wrAA))
[Answer]
# [Husk](https://github.com/barbuz/Husk), 11 bytes
```
!¡ȯΣṁḊ↑_2ŀ2
```
[Try it online!](https://tio.run/##ASAA3/9odXNr//8hwqHIr86j4bmB4biK4oaRXzLFgDL///8xMw "Husk – Try It Online")
## Explanation
```
!¡ȯΣṁḊ↑_2ŀ2
         ŀ2 array [0,1]
 ¡          iterate on the array, expanding it:
  ȯ         using the following 4 functions:
      ↑_2   get last 2 elements
    ṁḊ      get divisors of both
   Σ        sum them
!           Get element at index n
```
[Answer]
# [Factor](https://factorcode.org/) + `math.primes.factors math.unicode`, 53 bytes
```
[ 0 1 rot [ tuck [ divisors Σ ] bi@ + ] times drop ]
```
[Try it online!](https://tio.run/##JYy9CsIwGEX3PsXdhaCb1MVNXFzEqXSI@aGhaRK@fBF8Ht/HV4qpnQ5czrlWKo5UH/fr7dJjNhSMR56Ktd5gkTyJRG4xWdi/mLetBKei3gQkMszvpgXGqeuOdcAeB1BkDOCi5gbtXi6v@feDEU93xq6R12doigljVdJ7iPoD "Factor – Try It Online")
0-indexed.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 93 87 86 bytes
```
f(n){return n<2?n:s(f(n-1))+s(f(n-2));}s(n,c,i){for(c=i=0;n/++i;)c+=n%i?0:i;return c;}
```
[Try it online!](https://tio.run/##LY7NDoIwEITvfYoNhqQbihaPlMqLeDEt6Ca6GH5OhGfHBZnLTiZfZifkzxDWtdWMc9@MU8/A1bXmctCS5QVi9ndXRLcMmk0whHPb9Tp48tbxJcvIYcg8p1TbktxRE9yynojDe4oNVMMYqTu/bop4hM@DWKOaFYikCvSWEniwTk7loRAjvbgTm769IK1O0lhCGu@cGCADrSaZpXbqeGudWtYf "C (gcc) – Try It Online")
A simple recursive solution that finds divisors by brute force.
Thanks to @ceilingcat for -6 bytes on the for loop and -1 on some superfluous parens.
[Answer]
# [Burlesque](https://github.com/FMNSSun/Burlesque), 23 bytes
```
0 1 2{fc++jfc++.+}C~j!!
```
[Try it online!](https://tio.run/##SyotykktLixN/V@U@d9AwVDBqDotWVs7C0Toadc612UpKv7/b2gMAA "Burlesque – Try It Online")
```
0 1   # Initial 
2     # Keep top 2 stack elements
{
 fc++ # Factors, Sum
 j    # Swap stack
 fc++ # Factors, Sum
 .+   # Sum
}C~   # Continue forever
j!!   # Get input element
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 7 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
1λè‚Ñ˜O
```
Outputs the 1-based \$n^{th}\$ value.
[Try it online.](https://tio.run/##yy9OTMpM/f/f8NzuwyseNcw6PPH0HH8g1wAA)
With some small modifications, we could output:
* **7 bytes:** The first 1-based \$n\$ values by replacing `è` with `£`: [try it online](https://tio.run/##yy9OTMpM/f/f8NzuQ4sfNcw6PPH0HH8g1xgA).
* **5 bytes:** The infinite 1-based sequence by removing the `1` and `è`: [try it online](https://tio.run/##yy9OTMpM/f//3O5HDbMOTzw9x///fwA).
* Or with 0-based sequence by adding `Ý` after the `1`:
	+ **8 bytes:** 0-based \$n^{th}\$: [try it online](https://tio.run/##yy9OTMpM/f/f8PDcc7sPr3jUMOvwxNNz/IEChgA).
	+ **8 bytes:** 0-based first \$n\$ values: [try it online](https://tio.run/##yy9OTMpM/f/f8PDcc7sPLX7UMOvwxNNz/IECJgA).
	+ **7 bytes:** 0-based infinite sequence: [try it online](https://tio.run/##yy9OTMpM/f/f8PDcc7sfNcw6PPH0HP///wE).
So with [default sequence rules](https://codegolf.stackexchange.com/tags/sequence/info), this could have been 5 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage).
**Explanation:**
```
 λ       # Start a recursive environment,
  è      # to output the a(input)'th value
         # (which is output implicitly at the end)
1        # Starting at a(0)=1
         # And where every following a(n) is calculated as:
   ‚     #  Pair the (implicit) previous two terms together: [a(n-2),a(n-1)]
         #  (a(n-2) is unknown in the first iteration, so will default to 0)
    Ñ    #  Get the divisors of both inner values
     ˜   #  Flatten this list of lists of integers
      O  #  Sum them together
```
**Explanation of the 5-bytes infinite 1-based sequence:**
```
λ        # Start a recursive environment,
         # to output the infinite sequence
         # (which is output implicitly at the end)
         # Implicitly starting at a(0)=1
         # And where every following a(n) is calculated as:
 ‚Ñ˜O    #  See above
```
[Answer]
# [Scala](https://www.scala-lang.org/), 123 bytes
Golfed version. [Attempt it online!](https://Scala%203,%20123%20bytes:%20%5B%60def%20f(n:Int):Int=if(n%3C3)1%20else%7Bdef%20g(n:Int,i:Int=1):Int=if(n%3E=i)if(n%25i%3C1)i+g(n,i+1)else%20g(n,i+1)else%200;g(f(n-1))+g(f(n-2))%7D%60%5D(https://ato.pxeger.com/run?1=VY7BDsFAEIbvnmIukp0UsVykVOIo4SRO4rBq24zUlu6QCJ7EpQ68k7exbYm47L___38zu7enDVWiuvnrkq42OmSYKjJwrgGsdQRbZ4TKYuvDKMvUaTHjjEy8RB_mhhiCkgQ4qgSs3h-0CbULhQROQbaxtVU7EWGL0wlZLtGdW8CJEV8cXXp9HDhq9l7n4s1IGH9sGIsjIOcGXZSgE6vLOq7qBpW9_GHDgLDQOg0kkue4BnkSi0H4M-1-LBzXlIhedesgfr5w_2ieV_oG))
```
def f(n:Int):Int=if(n<3)1 else{def g(n:Int,i:Int=1):Int=if(n>=i)if(n%i<1)i+g(n,i+1)else g(n,i+1)else 0;g(f(n-1))+g(f(n-2))}
```
Ungolfed version. [Attempt it online!](https://Scala%203,%20342%20bytes:%20%5B%60object%20Main%20%7B%20%20%20def%20main(args:%20Array%5BString%5D):%20Unit%20=%20%7B%20%20%20%20%20val%20sequence%20=%20(1%20to%2010).map(f).toList%20%20%20%20%20println(sequence)%20%20%20%7D%20%20%20%20def%20f(n:%20Int):%20Int%20=%20%7B%20%20%20%20%20if%20(n%20%3C%203)%201%20%20%20%20%20else%20g(f(n%20-%201))%20+%20g(f(n%20-%202))%20%20%20%7D%20%20%20%20def%20g(n:%20Int,%20i:%20Int%20=%201):%20Int%20=%20%7B%20%20%20%20%20if%20(n%20%3E=%20i)%20%7B%20%20%20%20%20%20%20if%20(n%20%25%20i%20%3C%201)%20i%20+%20g(n,%20i%20+%201)%20%20%20%20%20%20%20else%20g(n,%20i%20+%201)%20%20%20%20%20%7D%20else%200%20%20%20%7D%20%7D%20%60%5D(https://ato.pxeger.com/run?1=bZBBSwMxEIXxur_iXYQMtqWxF1lawaNgT6IX8RDXZEnZztbNtCCyv8RLL_qj_DXGNFsoeMlkPh7vDe_zO1SmMbP9_msrbnz1c_bYvqxsJVgaz_gogFfrsI6LMl0dStx0nXl_upfOc_1MJR7YCxZJCexMg2DftpYrG6HSkBZ6SpO12ShHE2nvfJAk3UQDaVgNcoq0L3KeU1ziloXSe7T3Dooxx4ygE7BNsKhVlGMMTYSL43ZJJ451dhzBD576X_frBTxlMrBz-JiqKY6_AB6lj6Ysylec4v6Ap-mIvjjUm1se2v4F))
```
object Main {
  def main(args: Array[String]): Unit = {
    val sequence = (1 to 10).map(f).toList
    println(sequence)
  }
  def f(n: Int): Int = {
    if (n < 3) 1
    else g(f(n - 1)) + g(f(n - 2))
  }
  def g(n: Int, i: Int = 1): Int = {
    if (n >= i) {
      if (n % i < 1) i + g(n, i + 1)
      else g(n, i + 1)
    } else 0
  }
}
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 11 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Starts with `0` and outputs the `n`th term, zero-indexed. Replace `g` with `h` to output the first `n` terms instead.
```
@Zo2 câ x}g
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=QFpvMiBj4iB4fWc&input=MTM)
]