본문 바로가기

Algorithm8

Problem 16 - Power digit sum 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? [출처 - projecteuler.net/] 이번에는 문제가 엄청 짧습니다. 문제만 본다면 단순하게 그냥 2에 대해서 거듭제곱을 계속하여 원하는 만큼 수행했을때, 결과값에 대해서 각 자리수에 대한 단순합을 구하는 문제입니다. 하지만 15번 거듭제곱을 수행하면, 누구는 그냥 머리도로 구할 수 있을 것 입니다. 2^10 * 2^5 = 1,024 * 32 = 32,768 이 되겠죠. 그럼 문제와 같이 각 자리수를 더해서 26을 바로 도출해 낼 수 있습니다. 하지만 1,000번이나 거듭제곱을 한다면..... 2020. 12. 7.
Problem 15 - Lattice paths Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner. How many such routes are there through a 20×20 grid? [출처 - projecteuler.net/] 이번 문제는 start 부터 end까지 가는 길의 경우의 가지 수를 구하는 문제가 되겠습니다. 그래도 중구난방에 장애물도 있고 그런 문제는 아니고... 그냥 정사각형의 grid에서 왼쪽꼭대기에서 오른쪽 바닥까지 이동하는 길의 가지 수 입니다. 다만 모든 길은 우/하 (즉 오른쪽 or 아래)로만 이동.. 2020. 12. 3.
Problem 14 - Longest Collatz sequence The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is though.. 2020. 12. 1.
Problem 2 - Even Fibonacci numbers 이번 문제는 Fibonacci 수의 특정값까지의 합을 구하는 문제입니다. 하지만 여기에는 조건이 몇가지 있습니다. 단순히 해당 문제를 풀기위한 방법과, Algorithm 문제를 푸는 방식으로 여러개의 Test_Case가 들어오고 약간 도전적인 목표의 특정값을 해결할 수 있도록 해보겠습니다. 1. 주어진 조건의 문제 해결 제약조건은 아래와 같습니다. 400만 이하의 Fibonacci를 대상으로 함 그 중에서 짝수인 값의 합을 구함 저는 우선 Fibonacci가 400만까지 가려면 얼마나 많은 단계를 거쳐야 하는지 궁금해졌습니다. 그래서 관련 코드를 대충 짜보면... a, b = 1, 2 cnt = 0 while True: temp = a + b if temp > 4000000: break print(tem.. 2019. 11. 19.