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

            国产精品无码久久四虎| 久久人人爽人人爽人人片AV东京热| 精品久久久久久无码中文野结衣 | 亚洲国产成人久久综合野外| 欧美亚洲另类久久综合婷婷 | 久久伊人五月丁香狠狠色| 人妻无码αv中文字幕久久琪琪布| 国产精品久久久香蕉| 久久久久亚洲av无码专区| 精品免费久久久久国产一区| 2021久久精品免费观看| 久久91综合国产91久久精品| 久久亚洲精品无码VA大香大香| 久久99精品国产自在现线小黄鸭 | 91精品国产91久久久久久蜜臀| 久久综合香蕉国产蜜臀AV| 精品国产91久久久久久久a| 亚洲国产精品无码久久久蜜芽| 久久亚洲中文字幕精品一区四 | 久久激情亚洲精品无码?V| 久久精品国产91久久综合麻豆自制| 久久午夜福利电影| 国产999精品久久久久久| 蜜臀久久99精品久久久久久小说 | 69国产成人综合久久精品| 久久久精品人妻一区二区三区四 | 99久久夜色精品国产网站| 欧美大战日韩91综合一区婷婷久久青草 | 精品久久久久久亚洲精品| 国产精品久久久久久久久软件| 99久久人人爽亚洲精品美女 | 一本色道久久88综合日韩精品| 久久精品国产只有精品2020| 精品永久久福利一区二区| 久久成人国产精品免费软件| 久久国产精品视频| 色综合久久久久网| 久久五月精品中文字幕| 日日狠狠久久偷偷色综合0 | 久久夜色精品国产噜噜亚洲AV| 免费无码国产欧美久久18|