본문 바로가기

분류 전체보기

(105)
[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++] 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..

반응형