# Tag Info

30

Score 100 8605 I used an algorithm that starts with one solution and repeatedly tries to split a prime $p$ in the solution into two other primes $q_ 1$ and $q_ 2$ that satisfy $\frac1{p-1} = \frac1{q_1-1}+\frac1{q_2-1}$. It is known (and can be quickly checked) that the positive integer solutions to $\frac1n = \frac1x + \frac1y$ are in one-to-one ...

24

JavaScript (V8), 54 bytes A full program that prints cuban primes forever. for(x=0;;){for(k=N=~(3/4*++x*x);N%++k;);~k||print(-N)} Try it online! NB: Unless you have infinite paper in your printer, do not attempt to run this in your browser console, where print() may have a different meaning. JavaScript (ES6),  63 61 60  59 bytes Returns the $... 14 MATL, 25 24 21 bytes Q:qJyZpbB!sEq*^YpYsXG Try it at MATL online Thanks @LuisMendo for a nice golfing session in chat that ultimately led to this 21 byte version, by suggesting Eq*^ Explanation Q:q % Push 0:n J % Push 1i for later use. y % Duplicate 0:n from below Zp % Vector result of isprime() b % Bubble 0:n from bottom of stack B!s % Sum of ... 14 Score 263 385 425 426 with only primes < 1.000.000 (was: non-competitive, now it is; score can be increased by running the program longer) I followed the same path as Wheat Wizard: iteratively search for primes in the solution that can be replaced with a longer list of primes with the same result. I wrote that Python program that does exactly this. It ... 13 Trial division: score 59407, 6243 layers, 16478 neurons in total Given as a Python program which generates and validates the net. See the comments in trial_division for an explanation of how it works. The validation is quite slow (as in, running time measured in hours): I recommend using PyPy or Cython. All layers use ReLU ($\alpha \to \max(0, \alpha)$) ... 12 Sledgehammer 0.4, 22 20 bytes ⢂⡐⠥⡄⠡⢒⣩⣀⣼⡝⢄⡎⣛⠅⡉⣱⡆⢀⡠⣽ Decompresses into this Wolfram Language function: ListPlot[AnglePath[Array[If[PrimeQ@#, ArcSin[(-1)^ThueMorse@#], 0] &, #]]] Ungolfed First we define a function that returns the angle to turn at each step: If[PrimeQ[#], ArcSin[(-1)^ThueMorse@#], 0 ]& ThueMorse is the parity of the sum ... 12 Score 32 34 36 {5, 7, 11, 13, 17, 23, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 101, 113, 131, 137, 151, 211, 229, 241, 281, 313, 379, 401, 433, 457, 491, 521, 571, 601, 25117, 293362609} This is an improvement of Arnauld's answer. I just noticed that$ \dfrac{1}{19-1}=\dfrac{1}{73-1}+\dfrac{1}{61-1}+\dfrac{1}{41-1} $But 41 and 61 were already used in ... 10 JavaScript (ES6), 45 44 bytes Takes input as (n)(p1), where$n$is 0-indexed. n=>g=(p,d=2)=>n?~p%d?g(p,d+1):--n?g(p*d):d:p Try it online! Commented n => // n = 0-based index of the requested term g = ( // g is a recursive function taking: p, // p = current prime product d = 2 ... 9 05AB1E, 6 bytes This produces and infinite output stream. λλP>fW Try it online! (link includes a slightly modified version, λ£λP>fW, which instead outputs the first$n$terms) Explanation Very straightforward. Given$p_1$and$n$, the program does the following: Starts with$p_1$as an initial parameter for the infinite stream (which is ... 8 Wolfram Language (Mathematica), 98 96 91 77 76 63 bytes ListPlot@AnglePath@Array[Pi/2If[PrimeQ@#,2ThueMorse@#-1,0]&,#]& -14 bytes: Thanks to @lirtosiast for showing me how to use AnglePath... -13 bytes: ...and ThueMorse! usage example: %[20000] Step-by-step explanation: If[PrimeQ@#, 2 ThueMorse@# - 1, 0] & is a function that takes the step ... 8 C (gcc), 179 bytes o;i;d;k;h;f(n,p)char*p;{h=2*n+1;memset(p,0,h*h);p+=h--*n+n;*p=1;for(d=k=0;k++<n;){for(i=1;k%++i%k;);for(o=k;o/2;o=o/2^o&1);i==k?d+=o*2+3:0;p+=(d%2*h+1)*((d&2)-1);*p=1;}return++h;} Try it online! A function. First argument is N, second argument is an allocated buffer of size at least$4 n^2 + 4 n + 1$bytes. A square image ... 8 Python 3,262 236 209 196 179 114 93 92 97 bytes def f(n): m=k=1;s='' while n:m*=k*k;k+=1;n-=m%k while k:s=chr(~-k%26+97)+s;k=~-k//26 return s Try it online! Fixed a bug mentioned by @benrg about getting a wrong output for the input 123. Thanks to: - @AdmBorkBork for help me getting started and save a few bytes - @Sriotchilism O'Zaic for saving me 6 ... 8 Score 22 Just to get the ball rolling. {5,7,11,13,17,19,23,31,37,41,43,47,53,59,61,67,71,79,137,491,25117,293362609} Compute the fraction I suspect that the sequence can be made arbitrary large, but my code is currently too messy and inefficient for anything significantly better than that. 7 Score 984314, 82027 layers, 246076 neurons in total We can keep things entirely in the integers if we use activation function ReLU, which simplifies the analysis. Given an input$x$which is known to be an integer, we can test whether$x = a$with two layers and three neurons: First layer: outputs$\textrm{ge}_a = (x - a)^+$and$\textrm{le}_a = (-...

7

Neim, 3 bytes ᚺ>: Explanation: ᚺ halve > increment : previous prime Try it online!

7

05AB1E, 16 12 9 bytes Generates an infinite list. Saved 4 bytes with Kevin Cruijssen's port of Arnaulds formula. Saved another 3 bytes thanks to Grimy ∞n3*4÷>ʒp Try it online! Explanation ∞ # on the list of infinite positive integers n3*4÷> # calculate (3*N^2)//4+1 for each ʒp # and filter to only keep primes

7

R, 75 73 bytes n=scan() while(F<n)F=F+any(!(((T<-T+1)*1:4-1)/3)^.5%%1)*all(T%%(3:T-1)) T Try it online! -2 bytes by noticing that I can remove brackets if I use * instead of & (different precedence). Outputs the nth Cuban prime (1-indexed). It uses the fact (given in OEIS) that Cuban primes are of the form $p=1+3n^2$ or $4p=1+3n^2$ for ...

7

MATL, 31 30 28 26 bytes J4:^0i:Zpl_G:B!s^*hYs)YsXG 3 Bytes saved thanks to @LuisMendo 2 Bytes saved thanks to @Sanchises Try it at MATL Online Explanation This solution uses complex numbers to represent the X and Y components of the 2D plane J % Push the literal complex number 0 + 1j to the stack 4: % Create the array [1, 2, 3, 4] ^ % ...

7

Python 3, 79 digits (probably optimal) A simple depth first search that allows up to two consecutive zeros. from sympy.ntheory.primetest import isprime def dfs(n=0, k=1): yield n if 100*n > k: yield from dfs(n, k*10) for i in range(1,10): if isprime(k*i + n): yield from dfs(k*i + n, k*10) l = 1 for prime in dfs()...

6

J, 15 bytes -10 bytes thanks to miles! Returning the sequence up to n (zero-indexed) – thanks to @miles (,0({q:)1+*/)^: Try it online! J, 25 bytes Returns the n th item _2{((],0{[:q:1+*/@])^:[]) Try it online!

6

Haskell, 1068 1042 1012 bytes -30, mostly from replacing if/then with guards. I'm sure it can be golfed more. data W=W[W]Int deriving Show f EQ y=y f x _=x m=1<0 k=1>0 []#[]=EQ []#_=LT _#[]=GT (W x y:z)#(W a b:d)=f(x#a)$f(compare y b)$z#d x?y=x#y>EQ b x=break(\(W y _)->y#x/=GT) x&[]=x d&(x@(W v w):u)=case b v d of(y,W f m:_)|f#v>LT-&...

5

Brachylog, 18 17 15 16 15 bytes ℕ₁<l4&≜sᶠ{Ḋ|ṗ}ᵐ Try it online! -1 byte after a discussion with Fatalize inspired me to just see what happens if I swap the l and the < around. This predicate generates the output through the input variable, so long as the output variable is left unconstrained. Since duplicates are allowed, each number is ...

5

Wolfram Language (Mathematica), 66 65 56 bytes (f=1+⌊3#/4#⌋&;For[n=i=0,i<#,PrimeQ@f@++n&&i++];f@n)& Try it online! J42161217 -1 by using ⌊ ⌋ instead of Floor[ ] attinat -1 by using ⌊3#/4#⌋ instead of ⌊3#^2/4⌋ -8 for For[n=i=0,i<#,PrimeQ@f@++n&&i++] instead of n=2;i=#;While[i>0,i-=Boole@PrimeQ@f@++n]

5

Perl 6, 213 182 bytes {my @p=[\+] [\*]({{.is-prime??.base(2).comb(~1)%2??i!!-i!!1+0i}(++$)}...*)[^$_];{"<svg viewBox='{.min xx 2,.elems xx 2}'>>.&{"L{.re} {.im}"}}' fill='none' stroke='black'/>"}(minmax |@p».reals)} {{"<svg viewBox='{{.min,.min,+$_,+$_}(.minmax)}'><path d='{"L"X~\$_}' fill='none' stroke='red'/></svg>"}(([\+] [\*]({-{...

5

Python 2, 56 bytes i=input();k=1 while 1: k*=i;print i;i=2 while~k%i:i+=1 Try it online! Commented i=input() # the initial prime k=1 # the product of all previous primes while 1: # infinite loop k*=i # update the product of primes print i # output the last prime i=2 # starting at two ... while~k%i: # find the lowest number that ...

5

05AB1E, 6 bytes <LʒfåP Takes the integer as first input, list as second. Includes the optional 1 in the output. Try it online or verify all test cases. Explanation: < # Decrease the (implicit) input by 1 L # Create a list in the range [1,input-1] ʒ # Filter it by: f # Get all prime factors of the current number (without ...

5

Stax, 6 bytes Ç─☼?▬µ Run and debug it at staxlang.xyz! Unpacked (7 bytes) and explanation: vf:Fn-! vf Filter range [1..n-1]: :F Distinct prime factors n- Remove all in provided list ! Is empty?

4

Brachylog, 18 bytes Another Brachylog solution. I couldn't get it shorter than Erik The Outgolfer's Brachylog solution; it's the exact same length, but approaches the generation from the opposite direction. {≜ℕ{sℕ₁₀}ᶠṗᵐ&}ᶠ⁵⁹b Looks like Unrelated String has beaten this by many a character, whom I congratulate. Explanation: {≜ℕ ...

4

APL (Dyalog Unicode), 36 47 48 49 47 43 28 bytes Takes an array of two integers a b and returns the Boolean value of the statement a+bi is a Gaussian integer. Edit: +11 bytes because I misunderstood the definition of a Gaussian prime. +1 byte from correcting the answer again. +1 byte from a third bug fix. -2 bytes due to using a train instead of a dfn. -4 ...

4

05AB1E, 4 bytes ;ÅPθ Try it online or verify first $[4,n]$ numbers. Explanation: Implementation of the observation @xnor's made in his comment: largest prime $\leq\frac{1}{2}n$. Which I've literally implemented now (after @Arnauld reported some bugs in my initial program): ; # Halve the (implicit) input ÅP # Get a list of primes smaller than ...

Only top voted, non community-wiki answers of a minimum length are eligible