2012年11月20日 星期二

vb選手第二次測試 2nd

請找出在long範圍內最大的兩個質數。

2 則留言:

  1. Dim notwant As Boolean
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As 1
    For i = 2147483647 To 2 Step -2
    For ii = 2 To i ^ 0.5
    If i Mod ii = 0 Then notwant = True: Exit For
    Next
    If notwant = False Then Print #1, i, i \ 2, i ^ 0.5: mycount = mycount + 1
    notwant = False
    If mycount = 1 Then Exit For
    Next
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim tof As Boolean
    Private Sub Form_Load()
    Me.Hide
    'Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    s = 0
    For i = 2147483647 To 1 Step -1
    tof = False
    For j = 2 To (i - 1) ^ 0.5
    If i Mod j = 0 Then tof = True: Exit For
    Next j
    If tof = False Then Print #2, i: s = s + 1
    If s = 2 Then End
    Next i
    Close #2
    Close #1
    End
    End Sub

    回覆刪除