본문 바로가기

python

Problem 45 - After 40755, what is the next triangle number that is also pentagonal and hexagonal? 링크 Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ... Pentagonal Pn=n(3n1)/2 1, 5, 12, 22, 35, ... Hexagonal Hn=n(2n1) 1, 6, 15, 28, 45, ... It can be verified that T285 = P165 = H143 = 40755. Find the next triangle number that is also pentagonal and hexagonal. python - ugly brute force limit = 100000 T = set([x*(x+1)/2 .. 더보기
Problem 44 - Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal. 링크 Pentagonal numbers are generated by the formula, Pn=n(3n1)/2. The first ten pentagonal numbers are: 1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ... It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 22 = 48, is not pentagonal. Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference is pentagonal and D = |Pk Pj| is minimised; what is the value.. 더보기
Problem 43 - Find the sum of all pandigital numbers with an unusual sub-string divisibility property. 링크 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 .. 더보기
Problem 42 - How many triangle words does the list of common English words contain? 링크 The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number.. 더보기
Problem 41 - What is the largest n-digit pandigital prime that exists? 링크 We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime. What is the largest n-digit pandigital prime that exists? python import itertools def isprime(n): if n == 1: return False if n < 4: return True if n & 1 == 0: return False if n < 9: return True if n % 3 == 0: return False r = int.. 더보기
Problem 40 - Finding the nth digit of the fractional part of the irrational number. 링크 An irrational decimal fraction is created by concatenating the positive integers: 0.123456789101112131415161718192021... It can be seen that the 12th digit of the fractional part is 1. If dn represents the nth digit of the fractional part, find the value of the following expression. d1 d10 d100 d1000 d10000 d100000 d1000000 Solved by pencil 1~9 9 of 1-digits numbers, total 9 digits 0 10 ~ 99 .. 더보기
Problem 39 - If p is the perimeter of a right angle triangle, {a, b, c}, which value, for p ≤ 1000, has the most solutions? 링크 If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120. {20,48,52}, {24,45,51}, {30,40,50} For which value of p 1000, is the number of solutions maximised? 참고 Problem 9 - "Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000" python import math import fractions ans = (0, 0) for p in range(12, 1001,.. 더보기
Problem 38 - What is the largest 1 to 9 pandigital that can be formed by multiplying a fixed number by 1, 2, 3, ... ? 링크 Take the number 192 and multiply it by each of 1, 2, and 3: 192 1 = 192 192 2 = 384 192 3 = 576 By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3) The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1.. 더보기
Problem 37 - Find the sum of all eleven primes that are both truncatable from left to right and right to left. 링크 The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3. Find the sum of the only eleven primes that are both truncatable from left to right and right to left. NOTE: 2, 3, 5, and 7 are not considered to b.. 더보기
Problem 36 - Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2. 링크 The decimal number, 585 = 10010010012 (binary), is palindromic in both bases. Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. (Please note that the palindromic number, in either base, may not include leading zeros.) python def binary(n): res = '' while n > 0: res += str(n % 2) n /= 2 return res def palindrom(k): b = binary(k) rb = b[::-1] retur.. 더보기