본문 바로가기

python

Problem 56 - Considering natural numbers of the form, ab, finding the maximum digital sum. 링크 A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1. Considering natural numbers of the form, ab, where a, b 100, what is the maximum digital sum? python - one line code max(sum(int(x) for x in str(a**b)) for a in range(1, 100) for b i.. 더보기
Problem 55 - How many Lychrel numbers are there below ten-thousand? 링크 If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindromes so quickly. For example, 349 + 943 = 1292, 1292 + 2921 = 4213 4213 + 3124 = 7337 That is, 349 took three iterations to arrive at a palindrome. Although no one has proved it yet, it is thought that some numbers, like 196, never produce a palindrome. A number that never forms a palindrome th.. 더보기
Problem 54 - How many hands did player one win in the game of poker? 링크 In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way: High Card: Highest value card. One Pair: Two cards of the same value. Two Pairs: Two different pairs. Three of a Kind: Three cards of the same value. Straight: All cards are consecutive values. Flush: All cards of the same suit. Full House: Three of a kind and a pair. Four of a .. 더보기
Problem 53 - How many values of C(n,r), for 1 ≤ n ≤ 100, exceed one-million? 링크 There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345 In combinatorics, we use the notation, 5C3 = 10. In general, nCr = n! r!(nr)! ,where r n, n! = n(n1)...321, and 0! = 1. It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066. How many, not necessarily distinct, values of nCr, for 1 n 100, are greater than on.. 더보기
Problem 52 - Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits in some order. 링크 It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order. Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits. 유명한 숫자 "142857" 이 답일 것이라 추측하면서.. 조금 생각해보면 x의 마지막 자리 숫자는 반드시 7이어야 한다는 것을 알 수 있다. 그리고 답은 6자리 숫자이며(이미 알고있는 142857이 정답의 상한이므로) 각 다지트는 {7, 4, 1, 8, 5, 2} 중 하나이다. 이 중 1은 첫번째 자리 디지트.. 더보기
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.. 더보기