본문 바로가기

Programming

(52)
[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++] BOJ #1017 - Prime pairs The problem “Prime Pairs” requires finding a pair of prime numbers for a given even number  n  such that the sum of the two prime numbers equals  n . This problem is a variation of the famous Goldbach’s conjecture, which states that every even integer greater than 2 can be expressed as the sum of two prime numbers.Problem Description:1. You are given an even number  n  ( \(n \geq 4\) ).2. The ta..
[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++] BOJ #1016 Square Nono Number Problem Description:You are given two integers, min and max, which define a range of numbers [min, max]. Your task is to find how many numbers within this range are not divisible by the square of any integer greater than 1. Such numbers are called “non-square-free” numbers.In mathematical terms, a number x in the range [min, max] is considered not square-free if there exists an integer k > 1 suc..
[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..