• <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 閱讀(323) 評論(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无码成人网站久久精品大| 亚洲AV无一区二区三区久久| 国产精品久久久久久吹潮| 国产精品久久久99| 久久狠狠爱亚洲综合影院| 国产精品久久久久久久| 亚洲精品97久久中文字幕无码| 久久精品人人做人人爽电影蜜月| 久久播电影网| 久久伊人精品青青草原高清| 伊人久久大香线蕉综合网站| 伊人久久大香线蕉精品| 久久久久久精品免费看SSS| 久久婷婷久久一区二区三区| 久久久久人妻一区二区三区| 99久久国产主播综合精品| 久久人妻少妇嫩草AV无码专区| 人妻中文久久久久| 91亚洲国产成人久久精品网址| 婷婷久久香蕉五月综合加勒比| 久久无码人妻精品一区二区三区 | 亚洲国产婷婷香蕉久久久久久| 久久久久久久久无码精品亚洲日韩 | 精品久久久久久亚洲精品| 精品久久人人爽天天玩人人妻| 国产午夜精品理论片久久 | 日韩中文久久| 国产精品99久久久久久董美香| 久久ZYZ资源站无码中文动漫 | 久久免费小视频| 国产午夜久久影院| 高清免费久久午夜精品| 久久久一本精品99久久精品66| 午夜精品久久影院蜜桃| 色播久久人人爽人人爽人人片aV | 伊人色综合久久天天人守人婷| 欧美麻豆久久久久久中文| 日本久久久久久久久久|