Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n,x - output
- 2,1 - 0 (since CD(2,1)={1,3}, distinct prime divisors={}, ravenity=0)
- 5,1 - 2
- 100,4 - 5
- 720,6 - 11
- ŒRḟ0*3+µÆfFœ-µQL
- ŒRḟ0*3+µÆfFœ-µQL Main link. Arguments, x, n
- ŒR Range; yield [-x, ..., x].
- ḟ0 Filter out 0.
- *3 Cube each remaining integer.
- + Add n to all cubes.
- µ Begin a new, monadic link. Argument: A (list of sums)
- Æf Factorize each k in A.
- F Flatten the resulting, nested list.
- œ- Perform multiset difference with A.
- If k in A is prime, Æf returns [k], adding on k too many to the
- flat list. Multiset difference with A removes exactly one k from
- the results, thus getting rid of primes.
- If k is composite (or 1), it cannot appear in the primes in the
- flat list, so subtracting it does nothing.
- µ Begin a new, monadic link. Argument: D (list of prime divisors)
- Q Unique; deduplicate D.
- L Compute the length of the result.
- l{st#mP+Q^d3s_BMSE
- l Length
- { Uniquify
- s Combine divisor lists
- t# Filter by if more than one element
- PM Take prime factorization of each number
- +RQ Add each num in list to input
- s_BM Each num in list and its negative (with bifurcate)
- ^R3 Cube each num in list
- SE Inclusive unary range - [1, 2, 3,... n] to input
- L3mD(«-Dp_Ïvyf`})Úg
- :3^t_h+tZp~)"@Yf!]vun
- : % take n implicitly. Generate [1,2,...,n]
- 3^ % raise to 3, element-wise
- t_h % duplicate, negate, concatenate horizontally: [1,2,...,n,-1,2,...-n]
- + % take x implicitly. Add to that array
- t % duplicate
- Zp % array that contains true for primes
- ~ % logical negate
- ) % apply index to keep only non-primes
- " % for each number in that array
- @ % push that number
- Yf! % prime factors, as a column array
- ] % end for each
- v % concatenate vertically all factors
- u % remove repeated factors
- n % number of elements of that array. Implicitly display
- #@~.@(,@:q:-.0&,)@:+(|#^&3)@i:
- f =: #@~.@(,@:q:-.0&,)@:+(|#^&3)@i:
- 100 f 4
- 5
- #@~.@(,@:q:-.0&,)@:+(|#^&3)@i:
- i: Range from -x to x
- ( )@ Apply this verb to the range:
- ^&3 a) every item cubed
- | b) absolute value of every item
- # c) every item in a) repeated b) times; this removes 0
- and produces some harmless duplication
- + Add n to every element of the resulting list
- ( )@: Apply this verb to the resulting vector:
- 0&, a) the vector with 0 appended
- ,@:q: b) flat list of prime divisors in the vector
- (and some extra 0s since we flatten an un-even matrix)
- -. c) list b) with elements of a) removed; this gets rid of
- the extra 0s and all primes that were in the list
- #@~.@ Remove duplicates and take length
- lambda r,n:len({z for z in{v for f in{t for u in[[r-q**3,r+q**3]for q in range(1,n+1)]for t in u if any(t%g<1 for g in range(2,t))}for v in range(2,f)if f%v<1}if all(z%g>0 for g in range(2,z))})
- (n,x)->omega(factorback(select(k->!isprime(k),vector(2*x,i,n+(i-(i<=x)-x)^3))))
- (n,x)->omega(factorback(select(k->!isprime(k),concat(vector(x,i,n-i^3),vector(x,i,n+i^3)))))
- ->(n,x){require'prime'
- v=((-x..x).to_a-[0]).map{|i|n+i**3}.reject{|e|Prime.prime?(e)}
- Prime.each(v[-1]).select{|i|v.any?{|e|e%i==0}}.size}
- a=range
- p=lambda n:any(n%x<1for x in a(2,n))
- r=lambda n,x:len(set(sum([[x for x in a(2,z+1)if z%x<1&1>p(x)]for z in filter(p,[n+z**3for z in a(-x,x+1)])],[])))
- def is_composite(n):
- return any(n % x == 0 for x in range(2, n))
- def prime_factors(n):
- return {x for x in range(2, n+1) if n % x == 0 and not is_composite(x)}
- def ravenity(n, x):
- nums = [n + z**3 for z in range(-x, x+1)]
- nums = filter(is_composite, nums)
- factors = map(prime_factors, nums)
- factors = sum(factors, [])
- #remove duplicates
- factors = set(factors)
- return len(factors)
- Tr[1^Union[First/@Join@@FactorInteger/@Select[z=Range@#2^3;Join@@{#-z,#+z},Not@*PrimeQ]]]&
- F[n_, x_] :=
- Length[Union[ (* number of unique elements *)
- First /@ (* drop multiplicities *)
- Join @@ (* join all prime factor lists *)
- FactorInteger /@ (* compute prime factors *)
- Select[ (* select those... *)
- Join @@ {n - Range[x]^3, n + Range[x]^3}, (* ...candidates... *)
- Not@*PrimeQ]]] (* ...that are not prime *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement