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

            Brian Warehouse

            Some birds aren`t meant to be caged, their feathers are just too bright... ...
            posts - 40, comments - 16, trackbacks - 0, articles - 1

            SGU 113 Nearly prime numbers

            Posted on 2010-08-17 13:23 Brian 閱讀(326) 評論(0)  編輯 收藏 引用 所屬分類: SGU

            Nearly prime number is an integer positive number for which it is possible to find such primes P1 and P2 that given number is equal to P1*P2. There is given a sequence on N integer positive numbers, you are to write a program that prints “Yes” if given number is nearly prime and “No” otherwise.

            Input

            Input file consists of N+1 numbers. First is positive integer N (1£N£10). Next N numbers followed by N. Each number is not greater than 109. All numbers separated by whitespace(s).

            Output

            Write a line in output file for each number of given sequence. Write “Yes” in it if given number is nearly prime and “No” in other case.
            不用管Nearly prime numbers 到底是個什么數,總之是兩個質數的乘積就對了。枚舉的范圍: 2 ~ 32000 (104.5 )
            我的思路是: 首先把2~32000之間的所有素數都存放在一個數組里,然后當你輸入一個數據時,先讓其逐一模除這個數組里的素數,一旦模除結果為0,則計算出他們的商,再判斷商是否也為素數。注意數據是兩個數的平方的處理

            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse#include <stdio.h>
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse#include 
            <math.h>
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            int prime[30000],M=0;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            int isP(int n) //判斷是否為素數,非常精確而高效
            SGU 113 Nearly prime numbers  - Icho - Brian WarehouseSGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse{
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            int i=2,t=sqrt(n);
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            if ((n != 2 && !(n % 2)) || (n != 3 && !(n % 3)) || 
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse        (n 
            != 5 && !(n % 5)) || (n != 7 && !(n % 7)))
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse        
            return 0;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            for (; i<=t; i++)
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse        
            if (n%== 0)
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse            
            return 0;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            return 1;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse}

            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            int isNP(int n)
            SGU 113 Nearly prime numbers  - Icho - Brian WarehouseSGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse{
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            int i=0,t=sqrt(n),r;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            for (; prime[i]<=t; i++// 平方在此處理
            SGU 113 Nearly prime numbers  - Icho - Brian WarehouseSGU 113 Nearly prime numbers  - Icho - Brian Warehouse
                SGU 113 Nearly prime numbers  - Icho - Brian Warehouse{
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse        
            if (n%prime[i] == 0// 模除試商
            SGU 113 Nearly prime numbers  - Icho - Brian WarehouseSGU 113 Nearly prime numbers  - Icho - Brian Warehouse
                    SGU 113 Nearly prime numbers  - Icho - Brian Warehouse{
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse            r
            =n/prime[i]; // 求商
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
                        if (isP(r))
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse                
            return 1;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse        }

            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    }

            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            return 0;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse}

            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            int main()
            SGU 113 Nearly prime numbers  - Icho - Brian WarehouseSGU 113 Nearly prime numbers  - Icho - Brian Warehouse
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse{
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            int i=3,N,m;    
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            for (prime[M++]=2; i<32000; i+=2)
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse        
            if (isP(i))
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse            prime[M
            ++]=i;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    scanf(
            "%d",&N);
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            while (N--)
            SGU 113 Nearly prime numbers  - Icho - Brian WarehouseSGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse{
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse        scanf(
            "%d",&m);
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse        
            if (m==6)
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse            printf(
            "Yes\n"); // 程序中唯一未解決的問題,望各路大牛指教!
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse
                    else printf("%s\n",isNP(m) ? "Yes":"No");
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    }

            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse    
            return 0;
            SGU 113 Nearly prime numbers  - Icho - Brian Warehouse}

            午夜欧美精品久久久久久久| 国产精品久久久久乳精品爆| 精品国产乱码久久久久软件| 久久99精品久久久大学生| 无码AV波多野结衣久久| 国产精品一区二区久久精品无码 | 久久精品国产99国产精品导航| 一本一本久久a久久综合精品蜜桃| 久久99精品久久久久久| 亚洲国产精品无码久久青草| 久久er国产精品免费观看2| 久久久久亚洲av成人无码电影| 久久久久久毛片免费播放| 久久久久99精品成人片牛牛影视| 三上悠亚久久精品| 亚洲欧美精品一区久久中文字幕| 久久福利青草精品资源站免费| 久久精品亚洲AV久久久无码| Xx性欧美肥妇精品久久久久久| 久久久亚洲欧洲日产国码aⅴ| 亚洲午夜福利精品久久| 精品久久久久久久久久久久久久久| 色综合久久综合中文综合网| 精品久久久中文字幕人妻| 无码国内精品久久人妻麻豆按摩| 色综合久久88色综合天天| 91精品国产9l久久久久| 97久久国产露脸精品国产 | 色综合久久久久综合体桃花网 | 久久91亚洲人成电影网站| 久久久久亚洲Av无码专| 中文字幕无码免费久久| 久久亚洲中文字幕精品一区| 久久久久久久综合狠狠综合| 亚洲另类欧美综合久久图片区| 久久久精品视频免费观看| 久久九九久精品国产免费直播| 品成人欧美大片久久国产欧美...| 亚洲综合精品香蕉久久网97| 欧美精品久久久久久久自慰| 亚洲午夜无码久久久久|