본문 바로가기

Programming/Project Euler

(72)
[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..
[C/C++] Project Euler #24 Lexicographic Permutations The problem in Project Euler #24 is to determine the millionth lexicographic permutation of the digits 0 through 9. Understanding the Method with Base SystemsHow do we calculate a number in a specific base system?For instance, to convert 723 to base 8:We repeatedly divide the number and record the remainders. Recalling middle school mathematics, this calculation is performed as follows:\( 723 \d..
[C/C++] Project Euler #23 - Non-Abundant Sums Project Euler #23 - Non-Abundant Sums asks the following:A number is classified as either a “Deficient number,” a “Perfect number,” or an “Abundant number” based on the sum of its proper divisors. If the sum of the proper divisors of a number is less than the number itself, it is classified as deficient. If the sum equals the number, it is called perfect. If the sum is greater than the number, i..
[C/C++] Project Euler #22 Names Scores The problem requires calculating the total of all name scores in a given text file containing names. The steps to solve the problem are:1. Parse the input file: Read a file that contains a single line of comma-separated names, each enclosed in double quotes.2. Sort the names alphabetically: Sort the list of names in ascending order.3. Compute name scores:• Assign a score to each name based on th..
[C/C++] Project Euler #21 Amicable Numbers This problem, while not at the level of a Millennium Problem, belongs to the realm of long-standing unsolved mathematical challenges, similar to the proof that no odd perfect number exists. Many people might already be familiar with the concept of a perfect number. A perfect number is defined as a number that equals the sum of its proper divisors (excluding itself). Examples include 6 and 28, wh..
[C/C++] Project Euler #20 Factorial Digit Sum The Factorial Digit Sum problem asks you to calculate the factorial of a given number and then compute the sum of all the digits in the resulting number. For example, 10! (10 factorial) equals \(10 \times 9 \times 8 \times \cdots \times 1 = 3,628,800,\) and the sum of its digits is \(3 + 6 + 2 + 8 + 8 + 0 + 0 = 27\). The problem specifically challenges you to find the sum of the digits of 100!. ..
[C/C++] Project Euler #19 Counting Sundays I believe this problem is designed to test whether you can correctly identify leap years.In C/C++, you can easily solve this problem using the `mktime()` function in the `time.h` header file. However, I tried to find a slightly different approach. (When using the `mktime()` function, I wonder if leap seconds are also calculated. The day of the week for 0:00:00 on the 1st day of the month in year..
[C/C++] Project Euler #18 Maximum Path Sum I(Dynamic Programming) This program seemed interesting to me personally.Problem 18 of Project Euler is about finding the path from the top to the bottom in a triangle of numbers that gives the maximum sum.Starting from the top number in the given triangle, you move downwards by selecting one of the two adjacent numbers. The goal is to find the path that gives the maximum sum of the numbers you choose along the way.The..

반응형