• <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
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理
            #include? < iostream >
            using ? namespace ?std;
            void ?main() {
            ?
            int ?h,g = 0 ;
            ?cout
            << " 請輸入范圍: " ;
            ?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ù)的實現(xiàn)代碼  回復(fù)  更多評論   

            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 << " 請輸入范圍: " ;
            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ù)的實現(xiàn)代碼  回復(fù)  更多評論   

            2006-04-25 11:16 by IvanCL

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

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

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

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

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

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

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

            2006-04-28 02:19 by
            用 篩

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

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

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

            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ù)的實現(xiàn)代碼  回復(fù)  更多評論   

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

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


            青青草国产精品久久久久| 久久精品国产亚洲AV香蕉| 久久久久久亚洲精品成人| 蜜臀av性久久久久蜜臀aⅴ麻豆| 亚洲av伊人久久综合密臀性色| 久久亚洲精品成人AV| 国产精品久久波多野结衣| 伊人久久大香线蕉综合热线| 亚洲AV无码久久寂寞少妇| 九九久久99综合一区二区| 国产亚洲精久久久久久无码77777| 精品国际久久久久999波多野| 久久婷婷五月综合色99啪ak| 久久精品a亚洲国产v高清不卡| 久久综合九色综合久99| 亚洲国产精品无码久久| 国产激情久久久久影院老熟女| 久久久久久久久久久久中文字幕| 国产精品激情综合久久| 麻豆AV一区二区三区久久| 色婷婷综合久久久久中文字幕| 久久福利青草精品资源站| 久久九九兔免费精品6| 少妇久久久久久被弄到高潮| 久久噜噜电影你懂的| 久久亚洲精品成人AV| 久久久久精品国产亚洲AV无码| 久久成人18免费网站| 久久久久亚洲?V成人无码| 久久青青草原精品国产软件 | 国产亚洲欧美精品久久久| 香港aa三级久久三级老师2021国产三级精品三级在 | 国产精品免费久久久久电影网| 久久久久无码精品国产| 日本久久久久亚洲中字幕| 亚洲日韩中文无码久久| 99精品国产综合久久久久五月天| 香蕉久久永久视频| 久久精品国产久精国产果冻传媒| 久久福利资源国产精品999| 思思久久精品在热线热|