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 d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:

  • d2d3d4=406 is divisible by 2
  • d3d4d5=063 is divisible by 3
  • d4d5d6=635 is divisible by 5
  • d5d6d7=357 is divisible by 7
  • d6d7d8=572 is divisible by 11
  • d7d8d9=728 is divisible by 13
  • d8d9d10=289 is divisible by 17

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

 

1406357289는 0에서 9까지 숫자로 구성되어 있으므로 0에서 9 pandigital 숫자이지만, 다소 재밌는 부분 문자열 속성을 가지고 있다.

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.

d1을 첫번째 문자, d2를 2번째 문자 등으로 부르면 다음을 알 수 있다:

  • d2d3d4=406은 2로 나눌 수 있음
  • d3d4d5=063은 3으로 나눌 수 있음
  • d4d5d6=635은 5로 나눌 수 있음
  • d5d6d7=357은 7로 나눌 수 있음
  • d6d7d8=572은 11로 나눌 수 있음
  • d7d8d9=728은 13으로 나눌 수 있음
  • d8d9d10=289은 17로 나눌 수 있음

이런 속성을 가진 0에서 9 pandigital 숫자의 합계는 얼마인가?

--------------------------------------------------------------------------

 

32번 문제로 처음 나와 이번에 4번째 나오는 pandigital 관련 문제의 난이도가 계속 올라간다.

 

반목문을 이용해 10자리 pandigital 숫자를 차례대로 만들고, 숫자를 3개씩 6개로 쪼개어서 각 숫자가 2, 3, 5, 7, 11, 13, 17로 나눠지는지 확인하여 해당하는 숫자의 합계를 구하면 된다.

 

숫자를 문자열/리스트로 바꾸는 것, 이것을 활용해 숫자의 일부를 잘라내는 것 등이 익숙해져 파이썬으로 답을 구하는 데 그리 어렵지 않았다. 성능 향상을 위해 4번째 숫자가 짝수인지만 확인해도 2로 나눠지는지 검증 가능하고, 6번째 자리고 0,5인지 확인해도 5로 나눠지는지 검증 가능하지만 큰 차이는 없을 것 갈아 다른 숫자와 동일한 형태로 3자리 숫자를 잘라내어 검증하는 형태로 구성했었다.

 

+ Recent posts