본문 바로가기

분류 전체보기

(103)
[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++] BOJ #1015 Sorting Numbers The problem BOJ #1015 - Sorting Numbers requires the following:You are given an array  A  of size  N . Your task is to create a permutation  P  of length  N  such that:1. Rearranged Order: When the elements of  A  are rearranged according to  P , they form a non-decreasing sequence. Specifically, if  B  is the rearranged array, then  B[i] = A[P[i]]  should hold, and  B  must be sorted in ascendi..
[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++] BOJ #1012 organic cabbages There are cabbages planted in your vegetable garden, and you want to grow them organically by releasing cabbage whiteworms. A single cabbage whiteworm is sufficient to prevent pests, as it can move to adjacent cabbages in the cluster.This problem is similar to the “number of islands” problem and other common problems. It can be solved using the basic DFS or BFS algorithms in graph theory. You ca..
[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++] BOJ #1011 Fly me to the Alpha Centauri This problem is about finding the minimum number of times a warp drive needs to be activated to travel to Alpha Centauri. Though it sounds like a space exploration problem, it essentially boils down to finding the largest number 'k' where the sum 1+2+3+...+k is less than half the distance to Alpha Centauri.Warping to Alpha CentauriAlpha Centauri is located approximately 4.37 light-years away fro..

반응형