密数序列


12

OEIS:A167171

密号是一个数字,具有完全一样多素因子作为无素因数(包括1和本身作为除数)。等效地,它是素数或两个不同素数的乘积。前100个密集数字为:

2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 31, 33, 34, 35, 37, 38, 39, 41, 43, 46, 47, 51, 53, 55, 57, 58, 59, 61, 62, 65, 67, 69, 71, 73, 74, 77, 79, 82, 83, 85, 86, 87, 89, 91, 93, 94, 95, 97, 101, 103, 106, 107, 109, 111, 113, 115, 118, 119, 122, 123, 127, 129, 131, 133, 134, 137, 139, 141, 142, 143, 145, 146, 149, 151, 155, 157, 158, 159, 161, 163, 166, 167, 173, 177, 178, 179, 181, 183, 185, 187, 191, 193, 194

给定一个非负整数n,输出dense(n)n可以是0索引或1索引。

参考实施(Sage)

import itertools

def dense_numbers():
    n = 1
    while True:
        prime_divisors = [x for x in divisors(n) if x.is_prime()]
        non_prime_divisors = [x for x in divisors(n) if not x.is_prime()]
        if len(prime_divisors) == len(non_prime_divisors):
            yield n
        n += 1

N = 20

print itertools.islice(dense_numbers(), N, N+1).next()

在线尝试


因此,许多素数序列......我不知道这么多的存在
β衰变

2
@βετѧΛєҫαγ另外还有素数称为六素数(͡°͜ʖ͡°)。
阿德南

@Adnan Oh myy; D
Beta Decay

的最大值是n多少?
R. Kap

@ R.Kap可以选择的语言最高。
Mego

Answers:


3

果冻,9 字节

ÆE²Sḍ2µ#Ṫ

从STDIN读取并使用基于1的索引。在线尝试!

怎么运行的

ÆE²Sḍ2µ#Ṫ  Main link. No arguments. Implicit argument: 0

      µ#   Read an integer n from STDIN and execute the chain to the left for
           k = 0, 1, 2, ... until n of them return a truthy value.
           Return the array of matches.
ÆE           Compute the exponents of k's prime factorization.
  ²          Square each exponent.
   S         Compute the sum of all squares.
    ḍ2       Test if 2 is divisible by the result (true iff  the sum is 1 or 2).
        Ṫ  Tail; extract the last (n-th) matching value of k.

2

实际上,12个字节

所有功劳归于丹尼斯的算法

`w♂N;*2%Y`╓N

在线尝试!

`w♂N;*2%Y`╓N

`        `     define a function
 w             prime factorization in exponent form:
               18 = (2^1)*(3^2) becomes [[2,1],[3,2]]
  ♂N           get the last element (exponent) of each sublist
    ;*         dot-product with self; equivalent to squaring
               each item and then taking the sum
      2%Y      test divisibility by 2
          ╓    first (input) solutions to the above function
           N   get the last element.

1

05AB1E,12 11字节

1索引

µ             # while counter != input
 NÑ           # get divisors of current number
   p          # check if prime
    D         # duplicate
     O        # sum one copy
      s_O     # invert and sum the other copy
         Q½   # if equal increase counter

在线尝试


1

Brachylog,17个字节

:1yt.
1<.=$p#dl<3

在线尝试!

谓词0(主谓词)

:1yt.
:1y     Find the first (input) solutions of predicate 1
   t    Last element
    .   Unify with output

谓词1(辅助谓词)

1<.=$p#dl<3
1<.            1 < output
  .=           assign a value to output
  . $p#d       output's prime factorization contains no duplicate
        l      and the length
         <3    is less than three

0

R,93字节

dense=function(n){a=b=0;for(i in which(!n%%1:n))if(which(!i%%2:i)+1==i)a=a+1 else b=b+1;a==b}

它倾向于发出警告。这不是一个真正的问题。允许警告可为我节省5个字节。

不打高尔夫球

dense=function(n){
     a=b=0                                #Initializing
     factors = which(!n%%1:n)             #Finds all factors
     for(i in factors)                    #Loops through factors
         prime = which(!i%%2:i)+1==i      #Tests if current factor is prime. If it is -- the first term in this vector will be TRUE. Otherwise, it will be false.
           if (prime) a=a+1 else b=b+1    #If first term is true, add 1 to a. Else add one to b. 
      return(a==b)                        #Test equality of a and b.
}

您不能使用+=运算符来保存2个字节吗?
R. Kap

遗憾的是,R没有任何有用的增量运算符,例如+=a++。有时可以有更短的方法(主要利用循环结构),但是我不知道这里有一种方法。
user5957401

0

Python,79个字节

f=lambda n,k=2:n<1or-~f(n-(sum((k%i<1)+2*(k%i**2<1)for i in range(2,k))<3),k+1)

使用基于1的索引。在Ideone上进行测试



0

公理,102字节

f(n:PI):PI==(i:=1;repeat(i:=i+1;a:=divisors(i);2*#[x for x in a|prime?(x)]=#a=>(n=1=>break;n:=n-1));i)

高低不平和结果

-- 1 base Indexed: return the n_th number i that has 2*#divisorsPrimeOf(i)=#divisors(i)
ff(n:PI):PI==
     i:=1
     repeat
        i:=i+1
        a:=divisors(i)
        2*#[x for x in a|prime?(x)]=#a=>(n=1=>break;n:=n-1)
     i

(3) -> [f(i)  for i in 1..23]
   (3)  [2,3,5,6,7,10,11,13,14,15,17,19,21,22,23,26,29,31,33,34,35,37,38]
                                               Type: List PositiveInteger
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.