Home » Math » Ulam spiral,Prime factors spiral

# Ulam spiral,Prime factors spiral

## Ulam spiral,prime spiral

```clc; clear all; close all;
sz  = 201;
mat = spiral(sz);
pm  = ~isprime(mat);
figure('Position',[0 0 800 800]);
imagesc(pm);
colormap bone;
caxis([0, 1]);axis off;```

## Prime factor colormap

Black dots are prime numbers. As lighter is the dot as higher is the number of prime factors of that number in the Ulam spiral.

```sz  = 201;
mat  = spiral(sz);
matf = zeros(sz);
for i = 1:sz
for j = 1:sz
fac = factor(mat(i,j));
fm = size(fac);
matf(i,j) = fm(2);
end
end
figure('Position',[0 0 800 800]);
imagesc(matf);
colormap hot;
caxis([1, max(matf(:))]);axis off;```

## Ulam spiral of prime number of prime factors

Black dots corespondend to the numbers in Ulam spiral which has a prime number of prime factors.

```sz  = 201;
mat  = spiral(sz);
matf = zeros(sz);
for i = 1:sz
for j = 1:sz
fac = factor(mat(i,j));
fm = size(fac);
matf(i,j) = fm(2);
end
end
figure('Position',[0 0 800 800]);
pm  = ~isprime(matf);
%sum(pm(:));
imagesc(pm);
colormap bone;
caxis([0, 1]);axis off;```