Algorithm: Print table of 500 primes

Algorithm P

Algorithm P (Print table of 500 primes). This algorithm has two distinct
parts: Steps P1-P8 prepare an internal table of 500 primes, and steps P9-P11
print the answer in the form shown above. The latter part of the program uses
two “buffers,” in which line images are formed; while one buffer is being printed,
the other is being filled.
P1. [Start table.] Set PRIME[1] <– 2, N <– 3, J <– 1. (In this program, N runs
through the odd numbers that are candidates for primes; J keeps track of
how many primes have been found so far.)
P2. [N is prime.] Set J <– J + 1, PRIME[J] <– N.
P3. [500 found?] If J = 500, go to step P9.
P4. [Advance N.] Set N <– N + 2.
P5. [K <– 2.] Set K <– 2. (PRIME[K] will run through the possible prime divisors
of N.)
P6. [PRIME[K] \N?] Divide N by PRIME[K]; let Q be the quotient and R the
remainder. If R = 0 (hence N is not prime), go to P4.
P7. [PRIME[K] large?] If Q <= PRIME[K], go to P2. (In such a case, N must
be prime; the proof of this fact is interesting and a little unusual – see
exercise 6.)
P8. [Advance K.] Increase K by 1, and go to P6.
P9. [Print title.] Now we are ready to print the table. Advance the printer
to the next page. Set BUFFER[0] to the title line and print this line. Set
B <– 1, M <– 1.
P10. [Set up line.] Put PRIME[M], PRIME[50 + M], …, PRIME[450 + M] into
BUFFER[B] in the proper format.
P11. [Print line.] Print BUFFER[B]; set B <– 1 - B (thereby switching to the
other buffer); and increase M by 1. If M <= 50, return to P10; otherwise the
algorithm terminates. |


Flow diagram

这里写图片描述


Java program

/**
 * Created with IntelliJ IDEA.
 * User: 1O1O
 * Date: 12/17/13
 * Time: 6:52 PM
 * :)~
 * Print table of 500 primes:ALGORITHMS
 */
public class Main {

    public static void main(String[] args) {
        int[] PRIME = new int[501];
        PRIME[1] = 2;
        int N=3;
        int J=1;

        /*Kernel of the Algorithm*/
        do{
            J++;                        /*P2*/
            PRIME[J] = N;
            if(J == 500){                 /*P3*/
                break;
            }
            do{
                N+=2;                        /*P4*/
                int K=2;                     /*P5*/
                int Q, R;                     /*P6*/
                do{
                    Q = N/PRIME[K];
                    R = N%PRIME[K];
                    if(R == 0){
                        break;
                    }
                    if(Q <= PRIME[K]){         /*P7*/
                        break;
                    }
                    K++;                      /*P8*/
                }while (true);
                if(R!=0 && Q <= PRIME[K]){
                    break;
                }
            }while (true);
        }while (true);

        /*Output the 500 PRIMES*/
        System.out.println("FIRST FIVE HUNDRED PRIMES:");
        System.out.print("   ");
        for(int i=1; i<=10; i++){
            System.out.print(String.format("%5s", i));
        }
        System.out.println();
        System.out.println();
        for(int M=1; M<=50; M++){
            System.out.print(String.format("%3s", M+":"));
            for(int j=0; j<500; j+=50){
                System.out.print(String.format("%5s", PRIME[j+M]));
            }
            System.out.println();
        }
    }
}

Outputs

FIRST FIVE HUNDRED PRIMES:
       1    2    3    4    5    6    7    8    9   10

 1:    2  233  547  877 1229 1597 1993 2371 2749 3187
 2:    3  239  557  881 1231 1601 1997 2377 2753 3191
 3:    5  241  563  883 1237 1607 1999 2381 2767 3203
 4:    7  251  569  887 1249 1609 2003 2383 2777 3209
 5:   11  257  571  907 1259 1613 2011 2389 2789 3217
 6:   13  263  577  911 1277 1619 2017 2393 2791 3221
 7:   17  269  587  919 1279 1621 2027 2399 2797 3229
 8:   19  271  593  929 1283 1627 2029 2411 2801 3251
 9:   23  277  599  937 1289 1637 2039 2417 2803 3253
10:   29  281  601  941 1291 1657 2053 2423 2819 3257
11:   31  283  607  947 1297 1663 2063 2437 2833 3259
12:   37  293  613  953 1301 1667 2069 2441 2837 3271
13:   41  307  617  967 1303 1669 2081 2447 2843 3299
14:   43  311  619  971 1307 1693 2083 2459 2851 3301
15:   47  313  631  977 1319 1697 2087 2467 2857 3307
16:   53  317  641  983 1321 1699 2089 2473 2861 3313
17:   59  331  643  991 1327 1709 2099 2477 2879 3319
18:   61  337  647  997 1361 1721 2111 2503 2887 3323
19:   67  347  653 1009 1367 1723 2113 2521 2897 3329
20:   71  349  659 1013 1373 1733 2129 2531 2903 3331
21:   73  353  661 1019 1381 1741 2131 2539 2909 3343
22:   79  359  673 1021 1399 1747 2137 2543 2917 3347
23:   83  367  677 1031 1409 1753 2141 2549 2927 3359
24:   89  373  683 1033 1423 1759 2143 2551 2939 3361
25:   97  379  691 1039 1427 1777 2153 2557 2953 3371
26:  101  383  701 1049 1429 1783 2161 2579 2957 3373
27:  103  389  709 1051 1433 1787 2179 2591 2963 3389
28:  107  397  719 1061 1439 1789 2203 2593 2969 3391
29:  109  401  727 1063 1447 1801 2207 2609 2971 3407
30:  113  409  733 1069 1451 1811 2213 2617 2999 3413
31:  127  419  739 1087 1453 1823 2221 2621 3001 3433
32:  131  421  743 1091 1459 1831 2237 2633 3011 3449
33:  137  431  751 1093 1471 1847 2239 2647 3019 3457
34:  139  433  757 1097 1481 1861 2243 2657 3023 3461
35:  149  439  761 1103 1483 1867 2251 2659 3037 3463
36:  151  443  769 1109 1487 1871 2267 2663 3041 3467
37:  157  449  773 1117 1489 1873 2269 2671 3049 3469
38:  163  457  787 1123 1493 1877 2273 2677 3061 3491
39:  167  461  797 1129 1499 1879 2281 2683 3067 3499
40:  173  463  809 1151 1511 1889 2287 2687 3079 3511
41:  179  467  811 1153 1523 1901 2293 2689 3083 3517
42:  181  479  821 1163 1531 1907 2297 2693 3089 3527
43:  191  487  823 1171 1543 1913 2309 2699 3109 3529
44:  193  491  827 1181 1549 1931 2311 2707 3119 3533
45:  197  499  829 1187 1553 1933 2333 2711 3121 3539
46:  199  503  839 1193 1559 1949 2339 2713 3137 3541
47:  211  509  853 1201 1567 1951 2341 2719 3163 3547
48:  223  521  857 1213 1571 1973 2347 2729 3167 3557
49:  227  523  859 1217 1579 1979 2351 2731 3169 3559
50:  229  541  863 1223 1583 1987 2357 2741 3181 3571

Reference

<< The Art of Computer Programming: Fundamental Algorithms >> VOLUME 1, DONALD E. KNUTH

标题基于Python的汽车之家网站舆情分析系统研究AI更换标题第1章引言阐述汽车之家网站舆情分析的研究背景、意义、国内外研究现状、论文方法及创新点。1.1研究背景与意义说明汽车之家网站舆情分析对汽车行业及消费者的重要性。1.2国内外研究现状概述国内外在汽车舆情分析领域的研究进展与成果。1.3论文方法及创新点介绍本文采用的研究方法及相较于前人的创新之处。第2章相关理论总结和评述舆情分析、Python编程及网络爬虫相关理论。2.1舆情分析理论阐述舆情分析的基本概念、流程及关键技术。2.2Python编程基础介绍Python语言特点及其在数据分析中的应用。2.3网络爬虫技术说明网络爬虫的原理及在舆情数据收集中的应用。第3章系统设计详细描述基于Python的汽车之家网站舆情分析系统的设计方案。3.1系统架构设计给出系统的整体架构,包括数据收集、处理、分析及展示模块。3.2数据收集模块设计介绍如何利用网络爬虫技术收集汽车之家网站的舆情数据。3.3数据处理与分析模块设计阐述数据处理流程及舆情分析算法的选择与实现。第4章系统实现与测试介绍系统的实现过程及测试方法,确保系统稳定可靠。4.1系统实现环境列出系统实现所需的软件、硬件环境及开发工具。4.2系统实现过程详细描述系统各模块的实现步骤及代码实现细节。4.3系统测试方法介绍系统测试的方法、测试用例及测试结果分析。第5章研究结果与分析呈现系统运行结果,分析舆情数据,提出见解。5.1舆情数据可视化展示通过图表等形式展示舆情数据的分布、趋势等特征。5.2舆情分析结果解读对舆情分析结果进行解读,提出对汽车行业的见解。5.3对比方法分析将本系统与其他舆情分析系统进行对比,分析优劣。第6章结论与展望总结研究成果,提出未来研究方向。6.1研究结论概括本文的主要研究成果及对汽车之家网站舆情分析的贡献。6.2展望指出系统存在的不足及未来改进方向,展望舆情
【磁场】扩展卡尔曼滤波器用于利用高斯过程回归进行磁场SLAM研究(Matlab代码实现)内容概要:本文介绍了利用扩展卡尔曼滤波器(EKF)结合高斯过程回归(GPR)进行磁场辅助的SLAM(同步定位与地图构建)研究,并提供了完整的Matlab代码实现。该方法通过高斯过程回归对磁场空间进行建模,有效捕捉磁场分布的非线性特征,同时利用扩展卡尔曼滤波器融合传感器数据,实现移动机器人在复杂环境中的精确定位与地图构建。研究重点在于提升室内等无GPS环境下定位系统的精度与鲁棒性,尤其适用于磁场特征明显的场景。文中详细阐述了算法原理、数学模型构建、状态估计流程及仿真实验设计。; 适合人群:具备一定Matlab编程基础,熟悉机器人感知、导航或状态估计相关理论的研究生、科研人员及从事SLAM算法开发的工程师。; 使用场景及目标:①应用于室内机器人、AGV等在缺乏GPS信号环境下的高精度定位与地图构建;②为磁场SLAM系统的设计与优化提供算法参考和技术验证平台;③帮助研究人员深入理解EKF与GPR在非线性系统中的融合机制及实际应用方法。; 阅读建议:建议读者结合Matlab代码逐模块分析算法实现细节,重点关注高斯过程回归的训练与预测过程以及EKF的状态更新逻辑,可通过替换实际磁场数据进行实验验证,进一步拓展至多源传感器融合场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值