본문 바로가기

Programming/Project Euler

(39)
[C/C++] Project Euler #34 - Digit Factorials This problem is about finding numbers that are equal to the sum of the factorials of their digits.For example, the number 145 is such a number because\[1! + 4! + 5! = 1 + 24 + 120 = 145\]This problem asks you to find the sum of all such numbers.If you've been working on Project Euler problems up to this point, you probably have some experience with extracting digits from a decimal number.In my c..
[C/C++] Project Euler #33 - Digit Cancelling Fractions Project Euler #33 problem is about “Digit Cancelling Fractions.” This problem involves finding fractions where both the numerator and denominator are two-digit numbers and satisfy a specific condition. The condition is that when the numerator and denominator share the same digit, and this digit is “cancelled” in a simple way, the resulting fraction must still equal the original fraction.For exam..
[C/C++] Project Euler #32 - Pandigital Products Project Euler #32 is a relatively low-difficulty problem with a difficulty level of 5%.A pandigital number is a number formed by using all digits within a specific range exactly once. For example, combinations such as 123456789 or 391867254, which include all digits from 1 to 9 exactly once, are called pandigital. In this problem, the condition requires using all digits from 1 to 9 exactly once...
[C/C++] Project Euler #31 - Coin Sums In the UK, the following coin denominations are available:• 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), £2 (200p).The goal is to find the number of unique combinations of these coins that sum to 200 pence (£2).Conditions:1. Coins can be used repeatedly as needed.2. The order of coins does not matter (e.g., {1p, 2p} is considered the same as {2p, 1p}).3. Only unique combinations should be counted. In t..
[C/C++] Project Euler #30 - Digit Fifth Powers Project Euler problem #30 is about finding numbers that are equal to the sum of the fifth powers of their digits. The problem specifies that single-digit numbers do not satisfy the condition, so the search must start with at least two-digit numbers.To solve this, you calculate the sum of the fifth powers of each digit of a given number and check if this sum equals the original number.  The goal ..
[C/C++] Project Euler #29 Distinct Powers This problem involves handling duplicates, but due to the large range of numbers, you’ll need to either use big integers for processing or come up with some other approach.To calculate the number of distinct \(a^b\) values, consider the following:For different a and b (where b > a), \(a^m\) and \(b^n\) will yield the same result only if b is a power of a. Otherwise, it’s impossible for the same ..
[C/C++] Project Euler #28 - Number Spiral Diagonals This program can actually work by defining the desired array, arranging the numbers, and then calculating the sum of the diagonals.Even if you do it this way, it doesn’t take a significant amount of time.However, when I first started writing these Project Euler posts, I focused on figuring out how to calculate more efficiently, so I tackled this problem by reducing its complexity.If you know how..
[C/C++] Project Euler #27 Quadratic Primes In the given quadratic formula \(n^2 + an + b\), n is an integer starting from 0, and a and b are integers satisfying the range |a| Summary:1. Find a and b such that the quadratic formula \(n^2 + an + b\) produces the maximum number of consecutive primes for n.2. Compute the product of these a and b.The quadratic formula \(n^2 + n + 41\) is a well-known example of a prime-generating quadratic. I..
[C/C++] Project Euler #26 Reciprocal Cycles This problem is about finding the longest recurring cycle. In fact, recurring cycles boil down to Euler’s totient function. The totient function can be defined and calculated as follows:If\[ n = \prod_{p_k \mid n} p_k^{a_k} \]then Euler’s totient function is given by:\[ \phi(n) = \prod_{p_k \mid n} (p - 1)p^{a_k - 1} \]In other words, if  n  is a composite number, the value of the totient functi..
[C/C++] Project Euler #25 1000-digit Fibonacci Number When learning C/C++ programming, one of the things everyone seems to try at least once is implementing the Fibonacci sequence. The Fibonacci sequence often appears in examples involving recursive functions and is also a frequent example for dynamic programming problems.The Fibonacci sequence originated from a quiz-like scenario about the growth of a rabbit population. However, it can also be app..