TI-BASIC 66 62字节
Ans→N:While X<N:IS>(A,A::A:prgmA:Ans→B:A²:prgmA:If B=Ans:IS>(X,N:End:A
sum(int(10fPart(Ans₁₀^(seq(⁻X-1,X,0,log(Ans
输入为 ñ在中Ans
。
输出为1索引 ñ序列中的第一个词。
辅助函数生成中的值的数字总和Ans
。
例子:
3:prgmCDGF1E
10
5:prgmCDGF1E
19
8:prgmCDGF1E
55
10:prgmCDGF1E
99
说明:
Ans→N:While X<N:IS>(A,A::A:prgmA:Ans→B:A²:prgmA:If B=Ans:IS>(X,N:End:A ;prgmCDGF1E
Ans→N ;store the input in N
While X<N ;loop until the Nth term has been reached
IS>(A,A: ;add 1 to A
; (Increment A and skip the next statement if A>A)
A ;leave A in Ans
prgmA ;call the helper program below
Ans→B ;store the result of the helper program in B
A² ;square A and leave the result in Ans
prgmA ;call the helper program below
; (result is in Ans)
If B=Ans ;if the two results are equal
IS>(X,N ;add 1 to X
; (Increment X and skip the next statement if X>N)
End
A ;leave A in Ans
;implicit print of Ans
sum(int(10fPart(Ans₁₀^(seq(⁻X-1,X,0,log(Ans ;prgmA
seq(⁻X-1,X,0,log(Ans ;generate a list...
; using X as the variable,
; starting at 0,
; ending at the log of Ans,
; and evaluating "⁻X-1" for each element
; (implicit increment of 1)
₁₀^( ;raise 10 to the power of each element
Ans ;multiply each element by the input
fPart( ;remove the integer part from each element
10 ;multiply each element by 10
int( ;round each element to the nearest integer
sum( ;then sum the resulting list
注意: TI-BASIC是一种标记化语言。字符数不不等于字节数。