전체 글 142

Project Euler #6 - Sum square difference

The sum of the squares of the first ten natural numbers is,12 + 22 + ... + 102 = 385The square of the sum of the first ten natural numbers is,(1 + 2 + ... + 10)2 = 552 = 3025Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.Find the difference between the sum of the squares of the first one hundred natural numbers ..

Project Euler #5 - Smallest multiple

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? 출처: https://projecteuler.net/ 1 ~ 20 사이의 어떤 수로도 나누어 떨어지는 가장 작은 수를 구하는 문제입니다. 이는 1~20 까지의 최소공배수를 구하는 방법으로 풀 수 있습니다. 최소 공배수를 구하는 방법에는 여러 가지가 있는데, 소인수분해를 이용하는 방법을 사용했습니다. 방법은 각 수를 모두 소인수분해한 후 공통인 소..

Project Euler #3 - Largest prime factor

The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ? 출처: https://projecteuler.net/ 600851475143의 소인수 중에서 가장 큰 수를 구하는 문제입니다.루트값 까지만 계산하는 방법으로 시간 복잡도를 줄여 풀었습니다. my solvingc++1234567891011121314151617181920212223242526272829303132333435#include #include using namespace std; typedef long long ll; vector getPrimeFactor(ll n) { vector ret; ll sqr..

Project Euler #2 - Even Fibonacci numbers

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. 출처: https://projecteuler.net/ 파보나치 수열 중 짝수이면서 4백만 이하인 모든 항을 더하는 문제입니다.쉬운 문제이지만 memoizatio..