본문 바로가기

problem solving

Problem 50 - Which prime, below one-million, can be written as the sum of the most consecutive primes? 링크 The prime 41, can be written as the sum of six consecutive primes: 41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive primes that adds to a prime below one-hundred. The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953. Which prime, below one-million, can be written as the sum of the most consecutive primes? pyth.. 더보기
Problem 49 - Find arithmetic sequences, made of prime terms, whose four digits are permutations of each other. 링크 The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another. There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence. What 12-digit nu.. 더보기
Problem 48 - Find the last ten digits of 1^1 + 2^2 + ... + 1000^1000. 링크 The series, 11 + 22 + 33 + ... + 1010 = 10405071317. Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000. python str(sum(x**x for x in range(1, 1001)))[-10:] c++ #include #include int main() { long long mod = 10000000000LL; long long ans = 0; for (int i = 1; i 더보기
Problem 47 - Find the first four consecutive integers to have four distinct primes factors. 링크 The first two consecutive numbers to have two distinct prime factors are: 14 = 2 7 15 = 3 5 The first three consecutive numbers to have three distinct prime factors are: 644 = 2² 7 23 645 = 3 5 43 646 = 2 17 19. Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers? python limit = 1000000 isPrime = [True] * limit isPrime[0] = isPrime.. 더보기
Problem 46 - Find the first four consecutive integers to have four distinct primes factors. 링크 It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. 9 = 7 + 212 15 = 7 + 222 21 = 3 + 232 25 = 7 + 232 27 = 19 + 222 33 = 31 + 212 It turns out that the conjecture was false. What is the smallest odd composite that cannot be written as the sum of a prime and twice a square? python limit = 10000 isPrime = [True] * limit.. 더보기
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.. 더보기