Private Sub Form_Load() Dim iCtr As Double Dim jCtr As Double Dim pCtr As String Dim sCtr As String
For iCtr = 3 To 10000000 jCtr = iCtr * iCtr sCtr = CSng(iCtr) If InStr(1, Right(jCtr, Len(sCtr)), iCtr) Then pCtr = pCtr & "," & iCtr End If Next iCtr pCtr = Right(pCtr, Len(pCtr) - 1) Debug.Print pCtr End Sub
Module Module1 Sub Main() Dim result = Enumerable.Range(3, 10000000 - 3).AsParallel(). Where(Function(x) x ^ 2 Mod 10 ^ (x.ToString().Length) = x).OrderBy(Function(x) x) result.ToList().ForEach(Sub(x) Console.WriteLine(x)) End SubEnd Module
5 6 25 76 376 625 9376 90625 109376 890625 2890625 7109376 Press any key to continue . . .
Dim i As Long, j As Integer, ij As Double Dim s As Double, c As String For i = 0 To 1000000 For j = 5 To 6 ij = 10 * i + j s = ij * ij c = CSng(ij) If InStr(1, Right(s, Len(c)), ij) Then Debug.Print ij Next j Next i结果: 5 6 25 76 376 625 9376 90625 109376 890625 2890625 7109376 一个守形数的个位数必定是 5 或 6,没有其他,因此个位只要 5 6 循环就行了,没必要0-9,提高效率。
Dim iCtr As Double
Dim jCtr As Double
Dim pCtr As String
Dim sCtr As String
For iCtr = 3 To 10000000
jCtr = iCtr * iCtr
sCtr = CSng(iCtr)
If InStr(1, Right(jCtr, Len(sCtr)), iCtr) Then
pCtr = pCtr & "," & iCtr
End If
Next iCtr
pCtr = Right(pCtr, Len(pCtr) - 1)
Debug.Print pCtr
End Sub
Dim result = Enumerable.Range(3, 10000000 - 3).AsParallel().
Where(Function(x) x ^ 2 Mod 10 ^ (x.ToString().Length) = x).OrderBy(Function(x) x)
result.ToList().ForEach(Sub(x) Console.WriteLine(x))
End SubEnd Module
6
25
76
376
625
9376
90625
109376
890625
2890625
7109376
Press any key to continue . . .
Dim i As Long, j As Integer, ij As Double
Dim s As Double, c As String
For i = 0 To 1000000
For j = 5 To 6
ij = 10 * i + j
s = ij * ij
c = CSng(ij)
If InStr(1, Right(s, Len(c)), ij) Then Debug.Print ij
Next j
Next i结果:
5
6
25
76
376
625
9376
90625
109376
890625
2890625
7109376 一个守形数的个位数必定是 5 或 6,没有其他,因此个位只要 5 6 循环就行了,没必要0-9,提高效率。