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

            USACO chapter 1 section 1..5 SuperPrime Rib

            USER: tianbing tianbing [tbbd4261]
            TASK: sprime
            LANG: C++
            Compiling...
            Compile: OK
            Executing...
            Test 1: TEST OK [0.011 secs, 2932 KB]
            Test 2: TEST OK [0.000 secs, 2932 KB]
            Test 3: TEST OK [0.000 secs, 2932 KB]
            Test 4: TEST OK [0.011 secs, 2932 KB]
            Test 5: TEST OK [0.011 secs, 2932 KB]
            All tests OK.
            

            Your program ('sprime') produced all correct answers! This is your submission #7 for this problem. Congratulations!

            Here are the test data inputs:

            ------- test 1 -------
            4
            ------- test 2 -------
            5
            ------- test 3 -------
            6
            ------- test 4 -------
            7
            ------- test 5 -------
            8
            
            Keep up the good work!
            
            Thanks for your submission!

            代碼:原來寫的代碼在怎么優化只能過四組數據。
                         查了一下才知道素數有如下規律:
            (來自NOCOW)            

            從數學的角度:
            1.首位只能是質數2 3 5 7

            2.其余位只能是1,3,7,9

            3.若n=1,直接輸出2,3,5 ,7
            這樣很快的就過了

            /*
            ID:tbbd4261
            PROG:sprime
            LANG:C++
            */

            #include
            <iostream>
            #include
            <fstream>
            #include
            <cmath>
            #include
            <time.h>
            using namespace std;
            int n;
            int isprime(int n)
            {   
            if(n<2)return 0;
                
            if(n==2)return 1;
                
            if(n%2==0)return 0;
                
            for(int i=3; i<=sqrt(n); i+=2)
                  
            if(n%i==0)return 0;
                
            return 1;
            }

            void dfs(int s,int k,ofstream &cout)
            {
             
            int i;
             
            if(!isprime(s))return;
             
            if(k==n)cout<<s<<endl;
             
            else for(i=1; i<=9; i+=2)
                   dfs(s
            *10+i,k+1,cout);
            }

            int main()
            {
                ifstream cin(
            "sprime.in");
                ofstream cout(
            "sprime.out");
               
            int t1=1,t2;
               cin
            >>n;
               dfs(
            2,1,cout);dfs(3,1,cout);dfs(5,1,cout);dfs(7,1,cout);
              
               
            //system("pause");
                return 0;
            }

             

            posted on 2010-06-07 23:17 田兵 閱讀(157) 評論(0)  編輯 收藏 引用 所屬分類: USACO

            <2010年5月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            導航

            統計

            常用鏈接

            留言簿(2)

            隨筆分類(65)

            隨筆檔案(65)

            文章檔案(2)

            ACM

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            成人久久综合网| 久久久久99精品成人片三人毛片| 久久精品国产亚洲av麻豆小说| 久久久精品人妻无码专区不卡| 久久精品国产亚洲一区二区| 久久精品国产亚洲AV麻豆网站| 99久久精品日本一区二区免费| 久久超乳爆乳中文字幕| 性高湖久久久久久久久AAAAA| 热久久最新网站获取| 精品久久一区二区| 人妻少妇久久中文字幕一区二区| 久久精品国产只有精品2020| 午夜精品久久久内射近拍高清| 国产∨亚洲V天堂无码久久久| 四虎影视久久久免费观看| 久久精品视频网| 蜜臀久久99精品久久久久久小说 | 久久人人妻人人爽人人爽| 国产视频久久| 久久精品亚洲欧美日韩久久| 久久精品国产秦先生| 久久久久中文字幕| 国産精品久久久久久久| 亚洲国产成人精品无码久久久久久综合| 欧美精品国产综合久久| 亚洲精品无码久久千人斩| 久久婷婷五月综合色奶水99啪 | 婷婷久久综合| 丁香五月网久久综合| 亚洲嫩草影院久久精品| 少妇无套内谢久久久久| 青青青青久久精品国产h| 亚洲国产二区三区久久| 色青青草原桃花久久综合| 日韩人妻无码精品久久免费一| 爱做久久久久久| 精品国产青草久久久久福利| 欧美亚洲国产精品久久蜜芽| 中文字幕亚洲综合久久2| 久久久久亚洲av毛片大 |