Cody

Problem 659. How long is the longest prime diagonal?

Stanislaw Ulam once observed that if the counting numbers are arranged in a spiral, the prime numbers contained in it form a surprising pattern. They appear to cluster along diagonals of the spiral matrix.

Given n, find the longest diagonal arrangement of primes in spiral(n).

Example:

 Input  n = 7
 Output d = 4

Since isprime(spiral(n)) is

     1     0     0     0     1     0     0
     0     0     0     1     0     0     0
     1     0     1     0     0     0     0
     0     1     0     0     1     1     0
     0     0     1     0     1     0     1
     0     1     0     0     0     1     0
     1     0     0     0     0     0     1

Solution Stats

53.36% Correct | 46.64% Incorrect
Last solution submitted on Aug 18, 2016

Problem Comments

Solution Comments

Tags

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more