1. 程式人生 > >2689 Prime Distance(2次用篩法)

2689 Prime Distance(2次用篩法)

The branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of number theoreticians for thousands of years is the question of primality. A prime number is a number that is has no proper factors (it is only evenly divisible by 1 and itself). The first prime numbers are 2,3,5,7 but they quickly become less frequent. One of the interesting questions is how dense they are in various ranges. Adjacent primes are two numbers that are both primes, but there are no other prime numbers between the adjacent primes. For example, 2,3 are the only adjacent primes that are also adjacent numbers. 
Your program is given 2 numbers: L and U (1<=L< U<=2,147,483,647), and you are to find the two adjacent primes C1 and C2 (L<=C1< C2<=U) that are closest (i.e. C2-C1 is the minimum). If there are other pairs that are the same distance apart, use the first pair. You are also to find the two adjacent primes D1 and D2 (L<=D1< D2<=U) where D1 and D2 are as distant from each other as possible (again choosing the first pair if there is a tie).

相關推薦

2689 Prime Distance2

The branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of number theoreticians for

POJ 2689 Prime Distance 素數

Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2689 Description

poj 2689 Prime Distance大數區間素數

題意:給定區間[L,R],求區間內距離最近的相鄰素數對和距離最遠的相鄰素數對,區間長度不超過1e6。 解題方案:用篩法求出[L,R]的所有素數——利用“合數n一定有小於或等於sqrt(n)的素數因子“這條性質,先預處理出sqrt(2,147,483,647)範圍內的所有素

Prime Distance素數

led question nds state rip input bsp round easy Description The branch of mathematics called number theory is about properties of

POJ 2689 Prime Distance素數區間--經典題

大致題意:給定[L,R]區間,找出區間內的每個素數 資料範圍 : 1<=L< R<=2,147,483,647) R-L <=1,000,000. R的數值太大,所以不能直接篩

POJ2689:Prime Distance大數區間素數

possible lib ios rop sel poj art eve led The branch of mathematics called number theory is about properties of numbers. One of the areas

找質數演算法Sieve of Eratosthenes

由於一個合數總是可以分解成若干個質數的乘積,那麼如果把質數(最初只知道2是質數)的倍數都去掉,那麼剩下的就是質數了。例如要查詢100以內的質數,首先2是質數,把2的倍數去掉;此時3沒有被去掉,可認為是質數,所以把3的倍數去掉;再到5,再到7,7之後呢,因為8,9,10剛才都

!POJ 2689 Prime Distance-卡時間-素數

題意:給定兩個數l,r求這之間最近和最遠的兩個素數。資料範圍是整數的上限。r-l<=10^6 分析:總思路是把l和r間的素數全部找出來,然後遍歷一遍求最小距離和最大距離。用一個函式預處理資料範圍內的所有素數是不現實的,一來陣列不可r能開那麼大二來會超時。想想素數篩的思

POJ 2689 - Prime Distance - [求素數]

代碼 one mini rop esc imu script less ogr 題目鏈接:http://poj.org/problem?id=2689 Time Limit: 1000MS Memory Limit: 65536K Description The branc

Prime DistancePOJ 2689

possible const code ini tin tput strong family name Description The branch of mathematics called number theory is about properties of num

POJ 2689 Prime Distance【素數

The branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of number theoreticia

POJ 2689 Prime Distance [選取素數]【數論】

題目連結:http://poj.org/problem?id=2689 ————————-. Prime Distance Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1

POJ 2689 - Prime Distance - [埃]

only namespace sting typedef led print it is visible define 題目鏈接:http://poj.org/problem?id=2689 Time Limit: 1000MS Memory Limit: 65536K

poj - 2689 Prime Distance

ans air stream string its put cau rime memset The branch of mathematics called number theory is about properties of numbers. One of the a

小作業戶登陸機會重試

valid 關閉 color body 密碼 put int 程序關閉 false 用戶登陸(三次機會重試) #print("請輸入賬號:%s\n 請輸入密碼:%s"%(inp_id,inp_pwd)) a = "2260683aaa" #這裏簡單了內置了一下用戶

POJ 2689 Prime Distance

The branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of n

【Coding】求素數的C++實現附100000以內素數表

#include <cstdio> #include <cstring> using namespace std; #define MAXN 1000000+100 bool arr[MAXN]; void findPrime(int

Sum of Consecutive Prime Numbers POJ - 2739 線性歐拉線性歐拉證明

sin nbsp ret 一個數 detail scan 就是 blog ace 題意:給一個數 可以寫出多少種 連續素數的合 思路:直接線性篩 篩素數 暴力找就行 (素數到n/2就可以停下了,優化一個常數) 其中:線性篩的證明參考:https://blog.csdn

POJ 3292 Semi-prime H-numbers類素數

Description This problem is based on an exercise of David Hilbert, who pedagogically suggested tha

3292 Semi-prime H-numbers素數

先求所有的H-pirme,所有的H-prime兩兩相乘打表。 注: 1、H-numbers是所有除以4餘1的數,而H-prime則是隻能在這些H-numbers中分解因式只得到1*本身的數(1除外)。所以9也是H-prime(原來理解錯了)。 2、 H-semi-prim