Microsoft Small Basic

Problem 7 of Project Euler

Modified: 2011/11/14 08:55 by 99.255.114.181 - Uncategorized
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6(th) prime is 13.

What is the 10001(st) prime number?

PrimeNumber = 10001

For i = 2 To 200000
  CheckPrime()
  If isPrime = "True" Then
    k = k + 1
    If k = PrimeNumber Then
      Goto ProgramEnd
    ElseIf Math.Remainder(K,10) = 0 Then
      TextWindow.WriteLine(i + " iterations, still looking for prime 10001. Have found " + k + " primes so far.")
    EndIf
  EndIf
EndFor

Sub CheckPrime
  isPrime = "True"
  
  For j = 2 To Math.SquareRoot(i)
    If Math.Remainder(i, j) = 0 Then
      isPrime = "False"
      Goto EndLoop
    EndIf
  EndFor
  EndLoop:
EndSub

ProgramEnd:
If k = PrimeNumber Then
  TextWindow.WriteLine("Prime number " + PrimeNumber + " is " + i)
Else
  TextWindow.WriteLine("The " + PrimeNumber + "st prime number was not found under " + (i-1) + ".")
EndIf

ScrewTurn Wiki version 2.0.35. Some of the icons created by FamFamFam.