user
The **arithmetic derivative** of an integer (more specifically, the
**Lagarias arithmetic derivative**) is a function defined for integers, based on prime
factorization, by analogy with the product rule for the derivative of a function that is
used in mathematical analysis. Accordingly, for natural numbers n, the arithmetic
derivative D(n) is defined as follows:

* D ( 0 ) = D ( 1 ) = 0 {\displaystyle {\displaystyle D(0)=D(1)=0}} . * D ( p ) = 1 for any prime p {\displaystyle {\displaystyle D(p)=1\;{\text{for any prime}}\;p}} . * D ( m n ) = D ( m ) n + m D ( n ) for any m , n ∈ N {\displaystyle {\displaystyle D(mn)=D(m)n+mD(n)\;{\text{for any}}\;m,n\in N}} . (Leibniz rule for derivatives).

Additionally, for negative integers the arithmetic derivative may be defined as 

−
D
(
−
n
)


for

(
n
<
0
)
{\displaystyle {\displaystyle -D(-n)\;{\text{for}}\;(n<0)}}
.

Examples

D
(
2
)
=
1
{\displaystyle {\displaystyle D(2)=1}}
 and 

D
(
3
)
=
1
{\displaystyle {\displaystyle D(3)=1}}
 (both are prime) so if 

m
n
=
2
⋅
3
{\displaystyle {\displaystyle mn=2\cdot 3}}
, then 

D
(
6
)
=
D
(
2
⋅
3
)
=
D
(
2
)
⋅
3
+
2
⋅
D
(
3
)
=
1
⋅
3
+
2
⋅
1
=
5
{\displaystyle {\displaystyle D(6)=D(2\cdot 3)=D(2)\cdot 3+2\cdot D(3)=1\cdot 3+2\cdot 1=5}}
.

D
(
9
)
=
D
(
3
)
⋅
3
+
3
⋅
D
(
3
)
=
1
⋅
3
+
3
⋅
1
=
6
{\displaystyle {\displaystyle D(9)=D(3)\cdot 3+3\cdot D(3)=1\cdot 3+3\cdot 1=6}}

D
(
27
)
=
D
(
3
)
⋅
9
+
3
⋅
D
(
9
)
=
1
⋅
9
+
3
⋅
6
=
27
{\displaystyle {\displaystyle D(27)=D(3)\cdot 9+3\cdot D(9)=1\cdot 9+3\cdot 6=27}}

D
(
30
)
=
D
(
5
)
⋅
6
+
5
⋅
D
(
6
)
=
1
⋅
6
+
5
⋅
5
=
31
{\displaystyle {\displaystyle D(30)=D(5)\cdot 6+5\cdot D(6)=1\cdot 6+5\cdot 5=31}}
.

Task

Find and show the arithmetic derivatives for -99 through 100.

Stretch task

Find (the arithmetic derivative of 

10

m
{\displaystyle {\displaystyle 10^{m}}}
) then divided by 7, where m is from 1 to 20.

See also

* OEIS:A003415 - a(n) = n' = arithmetic derivative of n. * Wikipedia: Arithmetic Derivative
assistant
```
use Prime::Factor;

multi D (0) { 0 }
multi D (1) { 0 }
multi D ($n where &is-prime) { 1 }
multi D ($n where * < 0 ) { -D -$n }
multi D ($n) { sum $n.&prime-factors.Bag.map: { $n × .value / .key } }


put (-99 .. 100).map(&D).batch(10)».fmt("%4d").join: "\n";

put '';

put join "\n", (1..20).map: { sprintf "D(10**%-2d) / 7 == %d", $_, D(10**$_) / 7 }

```

Output:

```
 -75  -77   -1 -272  -24  -49  -34  -96  -20 -123
  -1 -140  -32  -45  -22 -124   -1  -43 -108 -176
  -1  -71  -18  -80  -55  -39   -1 -156   -1  -59
 -26  -72   -1  -61  -18 -192  -51  -33   -1  -92
  -1  -31  -22  -92  -16  -81   -1  -56  -20  -45
 -14 -112   -1  -25  -39  -48   -1  -41   -1  -68
 -16  -21   -1  -60  -12  -19  -14  -80   -1  -31
  -1  -32  -27  -15  -10  -44   -1  -13  -10  -24
  -1  -21   -1  -32   -8   -9   -1  -16   -1   -7
  -6  -12   -1   -5   -1   -4   -1   -1    0    0
   0    1    1    4    1    5    1   12    6    7
   1   16    1    9    8   32    1   21    1   24
  10   13    1   44   10   15   27   32    1   31
   1   80   14   19   12   60    1   21   16   68
   1   41    1   48   39   25    1  112   14   45
  20   56    1   81   16   92   22   31    1   92
   1   33   51  192   18   61    1   72   26   59
   1  156    1   39   55   80   18   71    1  176
 108   43    1  124   22   45   32  140    1  123
  20   96   34   49   24  272    1   77   75  140

D(10**1 ) / 7 == 1
D(10**2 ) / 7 == 20
D(10**3 ) / 7 == 300
D(10**4 ) / 7 == 4000
D(10**5 ) / 7 == 50000
D(10**6 ) / 7 == 600000
D(10**7 ) / 7 == 7000000
D(10**8 ) / 7 == 80000000
D(10**9 ) / 7 == 900000000
D(10**10) / 7 == 10000000000
D(10**11) / 7 == 110000000000
D(10**12) / 7 == 1200000000000
D(10**13) / 7 == 13000000000000
D(10**14) / 7 == 140000000000000
D(10**15) / 7 == 1500000000000000
D(10**16) / 7 == 16000000000000000
D(10**17) / 7 == 170000000000000000
D(10**18) / 7 == 1800000000000000000
D(10**19) / 7 == 19000000000000000000
D(10**20) / 7 == 200000000000000000000
```