⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 primenumbers.vb

📁 这里是用VB写的数学库。以前用C、C++写的比较多。内容有:复数运算、矩阵运算、解方程、积分微分等。非常有用。
💻 VB
字号:
' We use classes from the Extreme.Mathematics.SpecialFunctions 
' namespace.
Imports Extreme.Mathematics.SpecialFunctions

Namespace Extreme.Mathematics.QuickStart.VB
    ' Illustrates working with prime numbers using the 
    ' NumberTheory class in the Extreme.Mathematics.SpecialFunctions 
    ' namespace of the Extreme Optimization Mathematics 
    ' Library for .NET.
    Module PrimeNumbers
        Sub Main()
            '
            ' Factoring numbers
            '

            ' The Factorize method returns an array containing the prime factors:
            Dim index As Int32
            Dim n As Int32 = 1001110110
            Dim factors As Int32() = NumberTheory.Factorize(n)

            Console.Write("{0} = {1}", n, factors(0))
            For index = 1 To factors.Length - 1
                Console.Write(" * {0}", factors(index))
            Next
            Console.WriteLine()

            ' Factors that occur multiple times is repeated as many times as necessary:
            n = 256 * 6157413
            factors = NumberTheory.Factorize(n)
            Console.Write("{0} = {1}", n, factors(0))
            For index = 1 To factors.Length - 1
                Console.Write(" * {0}", factors(index))
            Next
            Console.WriteLine()

            ' The 64bit version can safely factor numbers up to 48 bits long:
            Dim n2 As Int64 = 1296523 * 1177157L
            Dim factors2 As Int64() = NumberTheory.Factorize(n2)
            Console.Write("{0} = {1}", n2, factors2(0))
            For index = 1 To factors2.Length - 1
                Console.Write(" * {0}", factors2(index))
            Next
            Console.WriteLine()

            ' Let's try a longer number
            n2 = 4292017459171704241
            factors2 = NumberTheory.Factorize(n2)
            Console.Write("{0} = {1}", n2, factors2(0))
            For index = 1 To factors2.Length - 1
                Console.Write(" * {0}", factors2(index))
            Next
            Console.WriteLine()

            '
            ' Prime numbers
            '

            ' The IsPrime method verifies if a number is prime or not.
            n = 801853937
            Console.WriteLine("{0} is prime? {1}!", n, NumberTheory.IsPrime(n))
            n = 801853939
            Console.WriteLine("{0} is prime? {1}!", n, NumberTheory.IsPrime(n))

            ' MextPrime gets the first prime after a specified number. 
            ' You can call it repeatedly to get successive primes.
            ' Let's get the 10 smallest primes larger than one billion:
            Console.WriteLine("First 10 primes greater than 1 billion:")
            n = 1000000000
            For index = 1 To 10
                n = NumberTheory.NextPrime(n)
                Console.Write("{0,16}", n)
            Next
            Console.WriteLine()

            ' PreviousPrime gets the last prime before a specified number. 
            Console.WriteLine("Last 10 primes less than 1 billion:")
            n = 1000000000
            For index = 1 To 10
                n = NumberTheory.PreviousPrime(n)
                Console.Write("{0,16}", n)
            Next
            Console.WriteLine()

            Console.Write("Press Enter key to exit...")
            Console.ReadLine()
        End Sub

    End Module

End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -