43 lines
1.2 KiB
Text
43 lines
1.2 KiB
Text
Function sameDigits(Byval n As Integer, Byval b As Integer) As Boolean
|
|
Dim f As Integer = n Mod b : n \= b
|
|
While n > 0
|
|
If n Mod b <> f Then Return False Else n \= b
|
|
Wend
|
|
Return True
|
|
End Function
|
|
|
|
Function isBrazilian(Byval n As Integer) As Boolean
|
|
If n < 7 Then Return False
|
|
If n Mod 2 = 0 Then Return True
|
|
For b As Integer = 2 To n - 2
|
|
If sameDigits(n, b) Then Return True
|
|
Next b
|
|
Return False
|
|
End Function
|
|
|
|
Function isPrime(Byval n As Integer) As Boolean
|
|
If n < 2 Then Return False
|
|
If n Mod 2 = 0 Then Return n = 2
|
|
If n Mod 3 = 0 Then Return n = 3
|
|
Dim d As Integer = 5
|
|
While d * d <= n
|
|
If n Mod d = 0 Then Return False Else d += 2
|
|
If n Mod d = 0 Then Return False Else d += 4
|
|
Wend
|
|
Return True
|
|
End Function
|
|
|
|
Dim kind(2) As String ={"", "odd", "prime"}
|
|
For i As Integer = 0 To 2
|
|
Print Using "First 20 & Brazilian numbers: "; kind(i)
|
|
Dim Limit As Integer = 20, n As Integer = 7
|
|
Do
|
|
If isBrazilian(n) Then Print Using "& "; n; : Limit -= 1
|
|
Select Case kind(i)
|
|
Case "" : n += 1
|
|
Case "odd" : n += 2
|
|
Case "prime" : Do : n += 2 : Loop Until isPrime(n)
|
|
End Select
|
|
Loop While Limit > 0
|
|
Next i
|
|
Sleep
|