zoukankan      html  css  js  c++  java
  • nth prime number contain n as their substring within 100000000

    A small VBA code to get these numbers:

    1. Sub Main()
    2.     Dim i&, j&, k&, n&, num&, a(100000000) As Byte, p(1 To 10000000) As Long
    3.         num = 1
    4.      p(num) = 2    'The 1st prime
    5.     n = 100000000    '10^8
    6.     k = Int(Sqr(n)) 'sqrare root of n
    7.     For i = 3 To k Step 2
    8.         If a(i) = 0 Then
    9.             num = num + 1
    10.             p(num) = i
    11.             If InStr(i, num) Then Debug.Print "P(" & num & ")=" & i
    12.             For j = i * i To n Step 2 * i    'Eractosthenes
    13.                 a(j) = 100    'Not prime number
    14.             Next
    15.         End If
    16.     Next
    17.     For i = k + 1 To n Step 2    'List all prime numbers to array p()
    18.         If a(i) = 0 Then
    19.             num = num + 1
    20.             'p(num) = i
    21.             If InStr(i, num) Then Debug.Print "P(" & num & ")=" & i
    22.         End If
    23.     Next
    24. End Sub

    It returns:

    P(7)=17
    P(6455)=64553
    P(6456)=64567
    P(6457)=64577
    P(6459)=64591
    P(6460)=64601
    P(6466)=64661
    P(9551)=99551
    P(303027)=4303027
    P(440999)=6440999
    P(968819)=14968819
    P(5517973)=95517973

  • 相关阅读:

    如何找回自己!
    身体锻炼靶心心率!
    圣人言大任之人!
    如何修清净心?(净空老法师法语)
    vim 查询定位!
    深切悼念灾区遇难同胞!
    求后倒零
    植物大战僵尸【二分答案, 加贪心思想】
    植物大战僵尸【二分答案, 加贪心思想】
  • 原文地址:https://www.cnblogs.com/fengju/p/6336226.html
Copyright © 2011-2022 走看看