login
Numbers k such that k = (sum of digits of k)*((sum of digits of k) + 1).
0

%I #37 Jul 24 2021 01:12:01

%S 0,12,42,90,156

%N Numbers k such that k = (sum of digits of k)*((sum of digits of k) + 1).

%e 0 = 0*(0+1).

%e 12 = (1+2)*(1+2+1).

%e 42 = (4+2)*(4+2+1).

%e 90 = (9+0)*(9+0+1).

%e 156 = (1+5+6)*(1+5+6+1).

%t fQ[n_] := Block[{a = Plus @@ IntegerDigits@ n}, a*(a +1) == n]; Select[ Range[0, 1000], fQ] (* _Robert G. Wilson v_, Feb 24 2017 *)

%o (VBA)

%o Sub calcul()

%o Sheets("Result").Select

%o Range("A1").Select

%o For i = 1 To 10000000

%o Sum = 0

%o For k = 1 To Len(i)

%o Sum = Sum + Mid(i, k, 1)

%o Next

%o res = Sum * (Sum + 1)

%o If res = i Then

%o ActiveCell.Value = i

%o ActiveCell.Offset(1, 0).Select

%o End If

%o Next

%o End Sub

%K bref,base,fini,full,nonn

%O 1,2

%A _Shmelev Aleksei_, Feb 24 2017