Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to calculate print and save to file the first 100,000 prime numbers in VB.NET

1 Answer

0 votes

Download here the list of 100000 prime numbers

 

Imports System.IO

Module Module1

    Sub Main()

        Dim i As Integer
        Dim prime As Integer = 2
        Dim n As Integer = 100000
        Dim numbers As Integer = 1

        Using tw As TextWriter = File.CreateText("d:\\a_list_of_100000_prime_numbers.txt")
            While numbers <= n
                For i = 2 To prime - 1
                    If prime Mod i = 0 Then
                        Exit For
                    End If
                Next
                If i = prime Then
                    Console.WriteLine("{0}", prime)
                    tw.WriteLine(prime)
                    numbers = numbers + 1
                End If
                prime = prime + 1
            End While
        End Using

    End Sub

End Module

' run:
' 
' ...
'1296059
'1296077
'1296089
'1296101
'1296109
'1296137
'1296143
'1296167
'1296181
'1296187
'1296209
'1296227
'1296277
'1296283
'1296287
'1296293
'1296319
'1296331
'1296341
'1296343
'1296371
'1296391
'1296409
'1296413
'1296419
'1296467
'1296473
'1296481
'1296499
'1296511
'1296521
'1296523
'1296551
'1296557
'1296563
'1296571
'1296583
'1296587
'1296593
'1296601
'1296613
'1296623
'1296629
'1296649
'1296679
'1296689
'1296703
'1296721
'1296727
'1296749
'1296781
'1296787
'1296803
'1296817
'1296829
'1296833
'1296839
'1296877
'1296899
'1296907
'1296929
'1296949
'1296973
'1296983
'1297001
'1297003
'1297013
'1297019
'1297027
'1297057
'1297061
'1297063
'1297091
'1297103
'1297123
'1297129
'1297139
'1297147
'1297157
'1297169
'1297171
'1297193
'1297201
'1297211
'1297217
'1297229
'1297243
'1297249
'1297271
'1297273
'1297279
'1297297
'1297313
'1297333
'1297337
'1297349
'1297357
'1297367
'1297369
'1297393
'1297397
'1297399
'1297403
'1297411
'1297421
'1297447
'1297451
'1297459
'1297477
'1297487
'1297501
'1297507
'1297519
'1297523
'1297537
'1297561
'1297573
'1297601
'1297607
'1297619
'1297631
'1297633
'1297649
'1297651
'1297657
'1297669
'1297687
'1297693
'1297727
'1297739
'1297771
'1297781
'1297799
'1297841
'1297847
'1297853
'1297873
'1297927
'1297963
'1297973
'1297979
'1297993
'1298027
'1298039
'1298047
'1298053
'1298057
'1298111
'1298113
'1298117
'1298119
'1298131
'1298149
'1298161
'1298173
'1298191
'1298197
'1298221
'1298261
'1298279
'1298291
'1298309
'1298317
'1298329
'1298333
'1298351
'1298357
'1298371
'1298387
'1298467
'1298489
'1298491
'1298537
'1298551
'1298573
'1298581
'1298611
'1298617
'1298641
'1298651
'1298653
'1298699
'1298719
'1298723
'1298747
'1298771
'1298779
'1298789
'1298797
'1298809
'1298819
'1298831
'1298849
'1298863
'1298887
'1298909
'1298911
'1298923
'1298951
'1298963
'1298981
'1298989
'1299007
'1299013
'1299019
'1299029
'1299041
'1299059
'1299061
'1299079
'1299097
'1299101
'1299143
'1299169
'1299173
'1299187
'1299203
'1299209
'1299211
'1299223
'1299227
'1299257
'1299269
'1299283
'1299289
'1299299
'1299317
'1299323
'1299341
'1299343
'1299349
'1299359
'1299367
'1299377
'1299379
'1299437
'1299439
'1299449
'1299451
'1299457
'1299491
'1299499
'1299533
'1299541
'1299553
'1299583
'1299601
'1299631
'1299637
'1299647
'1299653
'1299673
'1299689
'1299709

 

Download here the list of 100000 prime numbers

 

 



answered May 13, 2016 by avibootz
edited May 13, 2016 by avibootz
...