전체 글 142

Project Euler #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? 출처: https://projecteuler.net/ 20*20 격자에서 좌측 상단에서 우측 상단까지 가는 경로의 개수를 구하는 문제입니다. (최소 경로)완전 탐색보다 나은 방법을 고민하다 20 x 20 즉 40개의 칸에서 20개의 길을 선택하는 문제이기에 이항계수로 풀면 되겠다는 생각이 들었습니다. 이항 계수는 재귀함수와 memoization..

Project Euler #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 → 1It 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 thought th..

Project Euler #12 - Highly divisible triangular number

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28We can see that 28 is the first triangle num..

Project Euler #11 - Largest product in a grid

In the 20×20 grid below, four numbers along a diagonal line have been marked in red.08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 24 47 32 60 99..

Project Euler #10 - Summation of primes

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million. 출처: https://projecteuler.net/ 2,000,000 이하 소수의 합을 구하는 문제입니다.앞전 문제와 마찬가지로 Eratosthenes' sieve 을 이용해 소수들을 구하는 방법으로 풀었습니다. my solvingc++1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#include #include #include using namespace std;typedef long long ll; bool isP..

Project Euler #8 - Largest product in a series

The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 6222989342338030813533627661428280644..

Project Euler #7 - 10001st prime

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.What is the 10 001st prime number? 출처: https://projecteuler.net/ 10,001번째의 소수를 구하는 문제입니다. 앞전 문제와 마찬가지로 Eratosthenes' sieve 을 이용해 소수들을 구하는 방법으로 풀었습니다. my solvingc++12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152#include #include using namespace std; b..