본문 바로가기

problem solving

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.. 더보기
Problem 35 - How many circular primes are there below one million? 링크 The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. How many circular primes are there below one million? python limit = 1000000 isPrime = [True] * limit isPrime[0] = isPrime[1] = False for i in range(2, int(round(limit**0.5))+1): .. 더보기
Problem 34 - Find the sum of all numbers which are equal to the sum of the factorial of their digits. 링크 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are equal to the sum of the factorial of their digits. Note: as 1! = 1 and 2! = 2 are not sums they are not included. python import math ans = 0 fac = [math.factorial(x) for x in range(0, 10)] for i in range(3, fac[9] * 7 + 1): if i == sum(fac[int(x)] for x in str(i)): ans += i print ans 더보기
Problem 33 - Discover all the fractions with an unorthodox cancelling method. 링크 The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s. We shall consider fractions like, 30/50 = 3/5, to be trivial examples. There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in th.. 더보기
Problem 32 - Find the sum of all numbers that can be written as pandigital products. 링크 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, the 5-digit number, 15234, is 1 through 5 pandigital. The product 7254 is unusual, as the identity, 39 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital. Find the sum of all products whose multiplicand/multiplier/product identity can be wri.. 더보기
Problem 31 - Investigating combinations of English currency denominations. 링크 In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). It is possible to make £2 in the following way: 1£1 + 150p + 220p + 15p + 12p + 31p How many different ways can £2 be made using any number of coins? python - dynamic programming items = [1, 2, 5, 10, 20, 50, 100, 200] mem = [0] * .. 더보기