# Sierpinski Number in Java

In this section, we will learn what is a Sierpinski number and also create Java programs to check if the given number is a Sierpinski number or not. The Sierpinski number program is frequently asked in Java coding interviews and academics. Before moving ahead in this section, first, we will understand the Sierpinski triangle because the Sierpinski number is closely connected to the Sierpinski triangle.

## Sierpinski Triangle

Sierpinski triangle or gasket triangle is a gematrical object that is self-similar. It means that if we zoom in on the object, it remains the same appearance or structure. One such fractal (a curve or geometric figure, each part of which has the same statistical character as the whole) is the Sierpinski triangle that is formed by drawing a triangle and removing an internal triangle drawn by connecting the midpoints of the outer tringle's sides. This process is repeated recursively and infinitum.

In other words, we can also define it as, "a fractal and attractive fixed set with the overall shape of an equilateral triangle. It subdivides a triangle into smaller triangles, recursively." The following figure shows the four-times iterated Sierpinski triangle.

The formula to count Sierpinski triangle is n=3k-1.

## Sierpinski Number

A Sierpinski number is a positive odd integer k, for which an integer k*2n+1 is all-composite for all-natural numbers n.

In other words, k will be a Sierpinski number if all the members of the following set are composite:

k.2n+1:n∈N

It is an OEIS sequence A076336. The first number of the sequence i.e. 78557 is the smallest Sierpinski number but it is a conjecture (not yet proved). It is a Sierpinski number because it has the covering set i.e., {3, 5, 7, 13, 19, 37, 73}. It is called a covering set because every number of the form 78557*2n+1 is divisible by one of these small primes.

The following table shows covering sets of first few Sierpinski numbers.

n Covering Set
78557 {3, 5, 7, 13, 19, 37, 73}
271129 {3, 5, 7, 13, 17, 241}
271577 {3, 5, 7, 13, 17, 241}
322523 {3, 5, 7, 13, 37, 73, 109}
327739 {3, 5, 7, 13, 17, 97, 257}
482719 {3, 5, 7, 13, 17, 241}
575041 {3, 5, 7, 13, 17, 241}
603713 {3, 5, 7, 13, 17, 241}
903983 {3, 5, 7, 13, 17, 241}
934909 {3, 5, 7, 13, 19, 73, 109}
965431 {3, 5, 7, 13, 17, 241}
1259779 {3, 5, 7, 13, 19, 73, 109}
1290677 {3, 5, 7, 13, 19, 37, 109}
1518781 {3, 5, 7, 13, 17, 241}
1624097 {3, 5, 7, 13, 17, 241}
1639459 {3, 5, 7, 13, 17, 241}
1777613 {3, 5, 7, 13, 17, 19, 109, 433}
2131043 {3, 5, 7, 13, 17, 241}

### Sierpinski Number Example

First few Sierpinski numbers are:

78557, 271129, 271577, 322523, 327739, 482719, 575041, 603713, 903983, 934909, 965431, 1259779, 1290677, 1518781, 1624097, 1639459, 1777613, 2131043, 2131099, 2191531, 2510177, 2541601, 2576089, 2931767, 2931991, 3083723, 3098059, 3555593, 3608251.

### Sierpinski Triangle Java Program

SierpinskiTriangleExample.java

Output:

Next TopicVigesimal in Java

For Videos Join Our Youtube Channel: Join Now