Created
August 26, 2012 05:23
-
-
Save nomeaning777/3474502 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'FreeBasic | |
Public Function Rotate(ByVal x As Integer) As Integer | |
Dim s As String = Str(x) | |
Return Int(Val(Mid(s,2,Len(s)-1) + Mid(s,1,1))) | |
End Function | |
Dim Shared isPrime(1000000) As Integer, Used(1000000) As Integer, Answer As Integer = 0 | |
For i As Integer = 0 To 1000000 | |
isPrime(i)=1 | |
Used(i)=0 | |
Next | |
isPrime(0) = 0: isPrime(1) = 0 | |
For i As Integer = 0 To 1000 | |
If isPrime(i) = 0 Then Continue For | |
For j As Integer = i * 2 To 1000000 Step i | |
isPrime(j) = 0 | |
Next | |
Next | |
For i As Integer = 0 To 1000000 | |
If isPrime(i) = 1 AndAlso Used(i) = 0 Then | |
Dim r As Integer = Rotate(i),Cnt As Integer = 1, Ok As Integer = 1 | |
If InStr(Str(i),"0") <> 0 Then Continue For | |
Used(i) = 1 | |
Do While r <> i | |
If isPrime(r) = 0 Then Ok = 0 | |
Used(r) = 1 | |
Cnt += 1 | |
r = Rotate(r) | |
Loop | |
If Ok = 1 Then Answer += Cnt | |
EndIf | |
Next | |
Print Answer | |
' #> 55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment