# Euler Problem 43

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.

Let d 1 be the 1 st digit, d 2 be the 2 nd digit, and so on. In this way, we note the following:

• d 2 d 3 d 4 =406 is divisible by 2
• d 3 d 4 d 5 =063 is divisible by 3
• d 4 d 5 d 6 =635 is divisible by 5
• d 5 d 6 d 7 =357 is divisible by 7
• d 6 d 7 d 8 =572 is divisible by 11
• d 7 d 8 d 9 =728 is divisible by 13
• d 8 d 9 d 10 =289 is divisible by 17

Find the sum of all 0 to 9 pandigital numbers with this property.

This one was a little tricky only because of the number of loops. My first brute force version technically worked albeit very slowly. So I moved if statements into each loop to filter out unecessary paths. Works now in < one second.

import java.util.*;

public class Euler43
{
public static void main(String[] args)
{
Euler43 e = new Euler43();
System.out.format(“Problem: %s\n”, e.getClass().getName());
}
public String Problem ()
{
ArrayList<String> P = new ArrayList<String>();
int [] Digits = new int [] {0,1,2,3,4,5,6,7,8,9};
int [] d = new int ;
boolean flag = true;
for (d = 1; d <= 9; d++)
for (d = 0; d <= 9; d++)
for (d = 0; d <= 9; d++)
for (d = 0; d <= 9; d++)
if ((d*100+d*10+d) % 2 == 0)
for (d = 0; d <= 9; d++)
if ((d*100+d*10+d) % 3 == 0)
for (d = 0; d <= 9; d++)
if ((d*100+d*10+d) % 5 == 0)
for (d = 0; d <= 9; d++)
if ((d*100+d*10+d) % 7 == 0)
for (d= 0; d <= 9; d++)
if ((d*100+d*10+d) % 11 == 0)
for (d = 0; d <= 9; d++)
if ((d*100+d*10+d) % 13 == 0)
for (d = 0; d <= 9; d++)
if ((d*100+d*10+d) % 17 == 0)
{
flag = true;
for (int digit: Digits)
{
int c = 0;
&
nbsp;                                     for (int i = 1; i <= 10; i++)
if (d[i] == digit)
c++;
if (c != 1)
{
flag = false;
break;
}
}
if (flag)
{
String val = “”;
for (int i = 1; i <= 10; i++)
val += d[i];
System.out.format(“%s\n”, val);