主题:分解质因数
我不记得什么时候写过了,所以又重新写了一次。
因为类型及字符串长度的限制,所以以单整形为限
DefInt A-Z
s$ = ZhiSu$(32760, 6)
Print fenjie$(9 * 8 * 13 * 5, s$, 6)
Function fenjie$(x, s$, n)
k$ = RTrim$(LTrim$(Str$(x))) + "="
If x = 0 Then
fenjie$ = "0=0"
Exit Function
ElseIf x < 0 Then
x = -x
k$ = k$ + "-1"
End If
i = 2
j = 1
Do Until x = 1
If x Mod i = 0 Then
x = x / i
If Right(k$,1)="=" Then k$=k$+LTrim$(Str$(i)) Else k$=k$+"*"+LTrim$(Str$(i))
Else
j = j + n
i = Val(Mid$(s$, j, n))
End If
Loop
fenjie$ = k$
End Function
Function ZhiSu$(x, n)
k$=Space$(n-1)+"2"+Space$(n-1)+"3"+Space$(n-1)+"5"+Space$(n-1)+"7"
For m = 11 To x Step 2
q = Sqr(m)
For i = n + 1 To Len(k$) Step n
r = Val(Mid$(k$, i, n))
If m Mod r = 0 Then Exit For
If r > q Then i = Len(k$) + n
Next
If i > Len(k$) Then k$ = k$ + Right$(Space$(n) + Str$(m), n)
Next
ZhiSu$ = k$ + " "
End Function
因为类型及字符串长度的限制,所以以单整形为限
DefInt A-Z
s$ = ZhiSu$(32760, 6)
Print fenjie$(9 * 8 * 13 * 5, s$, 6)
Function fenjie$(x, s$, n)
k$ = RTrim$(LTrim$(Str$(x))) + "="
If x = 0 Then
fenjie$ = "0=0"
Exit Function
ElseIf x < 0 Then
x = -x
k$ = k$ + "-1"
End If
i = 2
j = 1
Do Until x = 1
If x Mod i = 0 Then
x = x / i
If Right(k$,1)="=" Then k$=k$+LTrim$(Str$(i)) Else k$=k$+"*"+LTrim$(Str$(i))
Else
j = j + n
i = Val(Mid$(s$, j, n))
End If
Loop
fenjie$ = k$
End Function
Function ZhiSu$(x, n)
k$=Space$(n-1)+"2"+Space$(n-1)+"3"+Space$(n-1)+"5"+Space$(n-1)+"7"
For m = 11 To x Step 2
q = Sqr(m)
For i = n + 1 To Len(k$) Step n
r = Val(Mid$(k$, i, n))
If m Mod r = 0 Then Exit For
If r > q Then i = Len(k$) + n
Next
If i > Len(k$) Then k$ = k$ + Right$(Space$(n) + Str$(m), n)
Next
ZhiSu$ = k$ + " "
End Function