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

  • 相关阅读:
    C# 打印多页tif
    页面动态加载js文件
    CPrintDialog 构造函数参数详解
    DEVMODE 结构体
    对C#对象的Shallow、Deep Cloning认识【转】
    PowerShell 启动应用程序【转】
    中文网页的字体
    css3自适应布局单位vw,vh你知道多少?
    微信小程序轮播图宽高计算
    更改wordpress的默认登录页面名称wp-login
  • 原文地址:https://www.cnblogs.com/fengju/p/6336226.html
Copyright © 2011-2022 走看看