• <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   管理


            久久久久久久精品妇女99| 久久成人国产精品二三区| 日韩va亚洲va欧美va久久| 久久精品亚洲欧美日韩久久| 香蕉久久影院| 国产情侣久久久久aⅴ免费| 精品久久人人妻人人做精品| 久久综合亚洲鲁鲁五月天| 2021久久精品国产99国产精品| 久久久久国产视频电影| 亚洲中文久久精品无码ww16| 久久久网中文字幕| 久久国产精品久久国产精品| 久久亚洲精品成人无码网站| 91久久成人免费| 97久久超碰国产精品旧版| 伊人久久综合成人网| 久久无码精品一区二区三区| 丁香五月网久久综合| 亚洲国产精品一区二区久久hs | 2020久久精品国产免费| 一本一本久久a久久精品综合麻豆| 久久91综合国产91久久精品| 欧美午夜精品久久久久免费视| 无码任你躁久久久久久久| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 开心久久婷婷综合中文字幕| 国产成人精品久久免费动漫| 亚洲国产精品无码久久| 久久国产欧美日韩精品免费| 久久久久亚洲爆乳少妇无| 色综合久久最新中文字幕| 久久精品人人做人人爽97| 青青草原精品99久久精品66| 无码久久精品国产亚洲Av影片| 色欲综合久久躁天天躁| 亚洲成av人片不卡无码久久| 亚洲精品久久久www| 99久久夜色精品国产网站| 久久人与动人物a级毛片| 老色鬼久久亚洲AV综合|