• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Ivan

            交流能優(yōu)化思想。
            posts - 9, comments - 22, trackbacks - 0, articles - 0
               :: 首頁(yè) :: 新隨筆 ::  :: 聚合  :: 管理
            #include? < iostream >
            using ? namespace ?std;
            void ?main() {
            ?
            int ?h,g = 0 ;
            ?cout
            << " 請(qǐng)輸入范圍: " ;
            ?cin
            >> g;
            ?
            for ( int ?i = 2 ;i <= g;i ++ ) {
            ??h
            = 1 ;
            ??
            for ( int ?j = 2 ;j <= i;j ++ ) {
            ???
            if ((i % j? == ? 0 ) && (j != i)) {
            ????h
            = 0 ;
            ????
            break ;
            ???}

            ??}

            ??
            if (h)
            ??cout
            << i << endl;
            ?}

            }

            本人代碼不帶注釋,有需要了解者與本人聯(lián)系。

            Feedback

            # re: 求質(zhì)數(shù)的實(shí)現(xiàn)代碼  回復(fù)  更多評(píng)論   

            2006-04-24 21:21 by <font color="#FF00FF" >Stone Jiang
            #include < iostream >
            #include <math.h>
            using namespace std;
            void main() {
            int h,g = 0 ;
            cout << " 請(qǐng)輸入范圍: " ;
            cin >> g;
            for ( int i = 2 ;i <= g;i ++ ) {
            h = 1 ;
            for ( int j = 2 ;j <= sqrt( i);j ++ )
            {
            if ((i % j == 0 ) && (j != i)) {
            h = 0 ;
            break ;
            }
            }
            if (h)
            cout << i << endl;
            }
            }

            # re: 求質(zhì)數(shù)的實(shí)現(xiàn)代碼  回復(fù)  更多評(píng)論   

            2006-04-25 11:16 by IvanCL

            不用這么復(fù)雜吧。

            我覺(jué)得sqrt()不用也沒(méi)什么區(qū)別。

            # re: 求質(zhì)數(shù)的實(shí)現(xiàn)代碼  回復(fù)  更多評(píng)論   

            2006-04-25 21:47 by doylecnn
            除了sqrt可以減少循環(huán)次數(shù)外,質(zhì)數(shù)中除了2是偶數(shù)外,其余質(zhì)數(shù)均為奇數(shù),所以,可以把外邊兩個(gè)for循環(huán)都從=3開(kāi)始,i++和j++改成i+=2和j+=2(能被任何偶數(shù)整除,也能被2整除嘛)...這樣可以省掉更多次計(jì)算
            2?直接輸出來(lái)嘛...

            # re: 求質(zhì)數(shù)的實(shí)現(xiàn)代碼  回復(fù)  更多評(píng)論   

            2006-04-26 11:58 by Ivan
            ok 理解

            # re: 求質(zhì)數(shù)的實(shí)現(xiàn)代碼  回復(fù)  更多評(píng)論   

            2006-04-28 02:19 by
            用 篩

            # re: 求質(zhì)數(shù)的實(shí)現(xiàn)代碼  回復(fù)  更多評(píng)論   

            2008-04-27 00:18 by pandakim
            交個(gè)朋友 我也是寫(xiě)代碼的 現(xiàn)在大二

            # re: 求質(zhì)數(shù)的實(shí)現(xiàn)代碼  回復(fù)  更多評(píng)論   

            2010-05-05 14:30 by 劉廣平
            using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Text;

            namespace ZhiShu
            {
            class Program
            {
            static void Main(string[] args)
            {
            for (int number = 2; number < 1000; number++)
            {
            if(IsZhiShu(number))
            {
            Console.WriteLine("{0}不是質(zhì)數(shù)", number);
            }
            else
            {
            Console.WriteLine("{0}是質(zhì)數(shù)", number);
            }
            }
            }
            public static bool IsZhiShu(int Num)
            {
            int counter = 0;
            for (int i = 1; i < Num; i++)
            {
            int total = Num % i;
            if (total == 0)
            {
            counter++;
            }
            }
            if (counter > 1)
            return true;
            else
            return false;
            }
            }
            }

            # re: 求質(zhì)數(shù)的實(shí)現(xiàn)代碼  回復(fù)  更多評(píng)論   

            2012-12-23 16:38 by chchpd
            這樣時(shí)間復(fù)雜度太高啊!

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            怡红院日本一道日本久久 | 久久国产色AV免费看| 久久久久综合国产欧美一区二区 | 久久天天躁狠狠躁夜夜av浪潮| MM131亚洲国产美女久久| 久久久女人与动物群交毛片| 亚洲伊人久久大香线蕉综合图片| 无码八A片人妻少妇久久| 免费无码国产欧美久久18| 一本综合久久国产二区| 久久亚洲精品无码VA大香大香| 日本WV一本一道久久香蕉| 亚洲国产精品无码成人片久久| 久久久久久久97| 久久99精品久久久久久秒播| 久久久精品无码专区不卡| 亚洲欧美日韩久久精品| 2021国产精品久久精品| av午夜福利一片免费看久久| 青青草国产成人久久91网| 久久人人爽人爽人人爽av| 97久久婷婷五月综合色d啪蜜芽| 久久综合给久久狠狠97色| 亚洲国产精品人久久| 欧美日韩中文字幕久久久不卡| 亚洲精品乱码久久久久久中文字幕| 国产成人精品久久免费动漫| 久久久久久久国产免费看| 亚洲人成精品久久久久| 久久精品国产只有精品2020| 亚洲精品无码久久毛片| 久久国产欧美日韩精品| 亚洲国产精品无码久久青草| 亚洲级αV无码毛片久久精品 | 无码人妻久久一区二区三区免费| 狠狠狠色丁香婷婷综合久久俺| 久久国产视屏| 久久精品蜜芽亚洲国产AV| 久久只有这精品99| 97精品伊人久久久大香线蕉| 18岁日韩内射颜射午夜久久成人|