求1000到10000之间的素数,求到素数之后把所求的素数倒过来(如素数1009倒过来是9001),在判断倒过来的数是不是素数?急啊在线等啊!!
我自己的代码,没做完的,倒过来的数没求出来!!
Dim t As Integer
Dim r As Integer
Dim m As Integer
Dim n As Integer
Dim i As Integer
Dim j As Integer
Dim y(2000) As Integer
Dim x As Integer
x = 0
For i = 1000 To 9999
m = 1
For n = 2 To i / 2 - 1
If i Mod n = 0 Then m = 0
Next
If m = 1 Then
x = x + 1
y(x) = i
End If
Next
For x = 0 To 1061 Step 1
For r = 4 To 1 Step -1
t = 0
t = CInt(Mid(y(x), r, 1))
t = t * 10 ^ (r - 1)
j = j + t
Console.WriteLine(j)
Next
Next
[解决办法]
dim s() as integer ={}
dim count as integer=0
for i as integer =1000 to 99999
for j as integer =2 to i/2
if i Mod n = 0 then
count =0
exit for
else
count+=1
end if
next
if count > 0 then
redim preserve s(s.length)
s.(s.length-1)=i
next
for i as integer =0 to s.length-1
dim tmp() as char=s(i).ToString().ToCharArray()
array.Reverse(tmp)
if Array.indexof(s,cint(new string(tmp)))> =0 then '反转的数必定大于1000
Console.WriteLine(s(i))
end iif
next
[解决办法]
倒过来的数必定大于1000小于9999,那么只要倒过来的数在是1000-9999之间的素数就行了
[解决办法]
Dim tmp() As Char = s(i).ToString().ToCharArray()‘将数字转成Char数组
Array.Reverse(tmp) '反转数组
Array.IndexOf(s, CInt(New String(tmp))) '判断反转后的数字是否在前面在1000-9999的素数数组中