Guest User

Untitled

a guest
Aug 20th, 2019
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n,x - output
  2. 2,1 - 0 (since CD(2,1)={1,3}, distinct prime divisors={}, ravenity=0)
  3. 5,1 - 2
  4. 100,4 - 5
  5. 720,6 - 11
  6.  
  7. ŒRḟ0*3+µÆfFœ-µQL
  8.  
  9. ŒRḟ0*3+µÆfFœ-µQL Main link. Arguments, x, n
  10.  
  11. ŒR Range; yield [-x, ..., x].
  12. ḟ0 Filter out 0.
  13. *3 Cube each remaining integer.
  14. + Add n to all cubes.
  15. µ Begin a new, monadic link. Argument: A (list of sums)
  16. Æf Factorize each k in A.
  17. F Flatten the resulting, nested list.
  18. œ- Perform multiset difference with A.
  19. If k in A is prime, Æf returns [k], adding on k too many to the
  20. flat list. Multiset difference with A removes exactly one k from
  21. the results, thus getting rid of primes.
  22. If k is composite (or 1), it cannot appear in the primes in the
  23. flat list, so subtracting it does nothing.
  24. µ Begin a new, monadic link. Argument: D (list of prime divisors)
  25. Q Unique; deduplicate D.
  26. L Compute the length of the result.
  27.  
  28. l{st#mP+Q^d3s_BMSE
  29.  
  30. l Length
  31. { Uniquify
  32. s Combine divisor lists
  33. t# Filter by if more than one element
  34. PM Take prime factorization of each number
  35. +RQ Add each num in list to input
  36. s_BM Each num in list and its negative (with bifurcate)
  37. ^R3 Cube each num in list
  38. SE Inclusive unary range - [1, 2, 3,... n] to input
  39.  
  40. L3mD(«-Dp_Ïvyf`})Úg
  41.  
  42. :3^t_h+tZp~)"@Yf!]vun
  43.  
  44. : % take n implicitly. Generate [1,2,...,n]
  45. 3^ % raise to 3, element-wise
  46. t_h % duplicate, negate, concatenate horizontally: [1,2,...,n,-1,2,...-n]
  47. + % take x implicitly. Add to that array
  48. t % duplicate
  49. Zp % array that contains true for primes
  50. ~ % logical negate
  51. ) % apply index to keep only non-primes
  52. " % for each number in that array
  53. @ % push that number
  54. Yf! % prime factors, as a column array
  55. ] % end for each
  56. v % concatenate vertically all factors
  57. u % remove repeated factors
  58. n % number of elements of that array. Implicitly display
  59.  
  60. #@~.@(,@:q:-.0&,)@:+(|#^&3)@i:
  61.  
  62. f =: #@~.@(,@:q:-.0&,)@:+(|#^&3)@i:
  63. 100 f 4
  64. 5
  65.  
  66. #@~.@(,@:q:-.0&,)@:+(|#^&3)@i:
  67. i: Range from -x to x
  68. ( )@ Apply this verb to the range:
  69. ^&3 a) every item cubed
  70. | b) absolute value of every item
  71. # c) every item in a) repeated b) times; this removes 0
  72. and produces some harmless duplication
  73. + Add n to every element of the resulting list
  74. ( )@: Apply this verb to the resulting vector:
  75. 0&, a) the vector with 0 appended
  76. ,@:q: b) flat list of prime divisors in the vector
  77. (and some extra 0s since we flatten an un-even matrix)
  78. -. c) list b) with elements of a) removed; this gets rid of
  79. the extra 0s and all primes that were in the list
  80. #@~.@ Remove duplicates and take length
  81.  
  82. 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))})
  83.  
  84. (n,x)->omega(factorback(select(k->!isprime(k),vector(2*x,i,n+(i-(i<=x)-x)^3))))
  85.  
  86. (n,x)->omega(factorback(select(k->!isprime(k),concat(vector(x,i,n-i^3),vector(x,i,n+i^3)))))
  87.  
  88. ->(n,x){require'prime'
  89. v=((-x..x).to_a-[0]).map{|i|n+i**3}.reject{|e|Prime.prime?(e)}
  90. Prime.each(v[-1]).select{|i|v.any?{|e|e%i==0}}.size}
  91.  
  92. a=range
  93. p=lambda n:any(n%x<1for x in a(2,n))
  94. 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)])],[])))
  95.  
  96. def is_composite(n):
  97. return any(n % x == 0 for x in range(2, n))
  98.  
  99. def prime_factors(n):
  100. return {x for x in range(2, n+1) if n % x == 0 and not is_composite(x)}
  101.  
  102. def ravenity(n, x):
  103. nums = [n + z**3 for z in range(-x, x+1)]
  104. nums = filter(is_composite, nums)
  105. factors = map(prime_factors, nums)
  106. factors = sum(factors, [])
  107. #remove duplicates
  108. factors = set(factors)
  109. return len(factors)
  110.  
  111. Tr[1^Union[First/@Join@@FactorInteger/@Select[z=Range@#2^3;Join@@{#-z,#+z},Not@*PrimeQ]]]&
  112.  
  113. F[n_, x_] :=
  114. Length[Union[ (* number of unique elements *)
  115. First /@ (* drop multiplicities *)
  116. Join @@ (* join all prime factor lists *)
  117. FactorInteger /@ (* compute prime factors *)
  118. Select[ (* select those... *)
  119. Join @@ {n - Range[x]^3, n + Range[x]^3}, (* ...candidates... *)
  120. Not@*PrimeQ]]] (* ...that are not prime *)
RAW Paste Data