Microsoft Small Basic

Program Listing: DFQ430-0
' Prime factors
' Version 0.3
' Copyright © 2017-2018 Nonki Takahashi. The MIT License.
' Program ID DFQ430-0

max = 1000
n3 = 0
For n = 2 To max
PrimeFactor()
np = Array.GetItemCount(p)
ip = Array.GetAllIndices(p)
If np = 3 Then
dim = 0
For i = 1 To np
dim = dim + p[ip[i]]
EndFor
If dim = 3 Then
n3 = n3 + 1
TextWindow.Write("[" + n3 + "] ")
m = 1
For i = 1 To np
m = m * Math.Power(ip[i], p[ip[i]])
EndFor
If n = m Then
TextWindow.ForegroundColor = "Gray"
Else
TextWindow.ForegroundColor = "Red"
TextWindow.Write(" Overflow:")
EndIf
TextWindow.Write(n + "=")
For i = 1 To np
If 1 < i Then
TextWindow.Write("*")
EndIf
TextWindow.Write(ip[i])
If 1 < p[ip[i]] Then
TextWindow.Write("^" + p[ip[i]])
EndIf
EndFor
TextWindow.WriteLine("")
TextWindow.ForegroundColor = "Gray"
EndIf
EndIf
EndFor

Sub PrimeFactor
' calculate primes 2..n
' param n - positive integer
' return p[] - prime factors
Stack.PushValue("local", n)
If n = 1 Then
p = "1=1;"
ElseIf 1 < n Then
p = ""
While Math.Remainder(n, 2) = 0
p[2] = p[2] + 1
n = n / 2
EndWhile
For i = 3 To Math.SquareRoot(n) Step 2
While Math.Remainder(n, i) = 0
p[i] = p[i] + 1
n = n / i
EndWhile
EndFor
If 1 < n Then
p[n] = 1
EndIf
EndIf
n = Stack.PopValue("local")
EndSub