본문 바로가기

(임시휴재) Fanta's Post/Project Euler

16. 2^1000의 각 자리의 합은? 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 21000? 215 = 32768 이고 각 자리의 합은 3 + 2 + 7 + 6 + 8 = 26 이다. 21000의 각 자리 합은 몇인가? 배열 하나에 한자리수를 저장해서 긴 자리수를 계산합니다. #include #include #define SIZE 302 void add(int *a, int *b) { int i,j; for(i=SIZE-1; i>=0; i--) { a[i]+=b[i]; for(j=i; a[j]>=10; j--) { a[j-1]+=a[j]/10; a[j]-=a[j]/10*10; } } } vo.. 더보기
15. 20X20그리드의 좌상단에서 출발할 때 우하단으로 가는 길의 개수는? Starting in the top left corner of a 2X2 grid, there are 6 routes (without backtracking) to the bottom right corner. How many routes are there through a 20X20 grid? 2X2그리드의 좌상단에서 우하단으로 가는 길은 6개가 있다. 20X20그리드에선 몇개의 길이 있는가 파스칼의 삼각형을 이용해 풉니다. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 1C0 1C1 2C0 2C1 2C2 3C0 3C1 3C2 3C3 4C0 4C1 4C2 4C3 4C3 5C0 5C1 5C2 5C3 5C4 5C5 nXn그리드에서 길의 개수는 2nCn 입니다. #incl.. 더보기
14. 3n+1 The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) n → 3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is though.. 더보기
13. 100개의 50자리 수의 합에서 앞의 10자리 출력 이 숫자들의 합에서 앞의 10자리를 출력 37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629 91942213363574161572522430563301811072406154908250 23067588207539346171171980310421047513778063246676 89261670696623633820136378418383684178734361726757 28112879812849979408065481931592621691275889832738 442742289174325203.. 더보기
12. 500개 이상의 약수를 가진 트라이앵글 숫자는 무엇인가 The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28We can see that 28 is the first triangle n.. 더보기
11. 20X20그리드에서 인접한 4개의 수로 만들수 있는 가장 큰 곱이 뭘까? In the 20X20 grid below, four numbers along a diagonal line have been marked in red. 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 24 47 32 60 9.. 더보기
10. 200만 미만의 소수의 합을 구해 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. 10미만의 소수들의 합은 2 + 3 + 5 + 7 = 17이다. 200만 미만의 소수들의 합을 구하여라. 짝수인 소수는 2밖에 없으니 sum=2로 초기화 해주고 홀수만 확인합니다. is_prime함수도 홀수만 확인하니 i=3부터 나머지를 확인합니다. #include #include int is_prime(int a) { int i, sqrn=(int)sqrt(a); for(i=3; i 더보기
9. a+b+c=1000 을 만족하는 피타고라스의 수를 찾아라 A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. Pythagorean triplet은 세개의 자연수 a < b < c가 a2 + b2 = c2이 성립하는 것이다. 예를들어, 32 + 42 = 9 + 16 = 25 = 52와 같다. a + b + c = 1000. 조건을 만족하는 Pythagorean triplet를 찾고, 그것들의 곱 abc를 구하여라. a,.. 더보기
4. 두개의 3자리 수의 곱으로 만들 수 있는 가장 큰 palindrome을 찾아 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99. Find the largest palindrome made from the product of two 3-digit numbers. palindromic 숫자는 양쪽 어느 방향으로 읽어도 동일하다. 2자릿수에서 만들 수 있는 가장 큰 palindrome은 9009 = 91 * 99 3자릿수에서 만들 수 있는 가장 큰 palindrome을 찾아 세자리 숫자는 전부 다 곱해보면서 최대값을 찾습니다. #include #include int check(int n) { char.. 더보기
8. 1000개의 숫자안에서 다섯 숫자의 곱중 가장 큰 수를 찾아라 Find the greatest product of five consecutive digits in the 1000-digit number. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 3035890729629.. 더보기
7. 10001번째 소수를 찾아 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? 첫 여섯개의 소수를 나열하면 2, 3, 5, 7, 11, 13 이다. 우리는 6번째 소수가 13이란 걸 안다. 10001번째 소수를 찾아라 #include #include #include #include int prime[10002]; int is_prime_0(int a)//소수목록으로 확인 { int i; for(i=1; prime[i]; i++) if(a%prime[i]==0) return 0; return 1; } int is_prime_1(int a)//포인.. 더보기
6. 제곱의 합과 합의 제곱의 차이 The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence 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 numbe.. 더보기
5. 1부터 20까지의 숫자들로 나누어지는 가장 작은 수가 뭐야?? 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 number that is evenly divisible by all of the numbers from 1 to 20? 2520은 1부터 10까지의 수로 나머지 없이 나누어지는 가장 작은 수다. 1부터 20까지의 숫자들로 나누어지는 가장 작은 수가 뭐야?? 1부터 20까지의 최소공배수를 찾으면 됩니다. 참고 최대공약수와 최소공배수 long long gcd(long long u, long long v) { return (v==0)? u : gcd(v, u%v); } long lo.. 더보기
3. 가장 큰 소인수 찾기 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? 13195의 소인수는 5, 7, 13, 29다. 600851475143의 가장 큰 소인수는 무엇인가? 소수 판단 알고리즘처럼 600851475143의 제곱근에서 수를 감소하며 소인수인지 확인하면 됩니다. 가장 큰 소인수가 2일 리는 없으니 홀수만 검사합니다. #include #include int is_prime(int n) { int i, sqrn; sqrn = (int)sqrt(n); for (i = 2; i 더보기
2. 4000000 이하의 피보나치 수열 중 짝수들의 합 구하기 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, ... Find the sum of all the even-valued terms in the sequence which do not exceed four million. 피보나치의 새로운 항은 앞의 두 항을 더해 만들어진다. 1과 2로 시작하는 피보나치 수열의 처음 10개의 항: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... 4000000(4백만)이하의 피보나치 수열중 .. 더보기
1. 3또는 5의 배수 더하기 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. 10미만의 3또는 5의 배수를 찾으면 3, 5, 6, 9가 나온다. 1000미만의 3또는 5의 배수들의 합을 구해. 나머지연산으로 배수인지 확인만 하면 되는 간단한 문제입니다. #include int main() { int i, sum; for(sum=0, i=3; i 더보기