2019. 10. 8. 19:59
728x90

Counting Sundays

   

Problem 19

You are given the following information, but you may prefer to do some research for yourself.

  • 1 Jan 1900 was a Monday.
  • Thirty days has September, April, June and November.
    All the rest have thirty-one, Saving February alone,
    Which has twenty-eight, rain or shine. And on leap years, twenty-nine.
  • A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.

How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?


1901년 1월 1일 ~ 2000년 12월 31일까지 매월 1일이 일요일인 달이 몇 개인지 세는 문제.

1900년 1월 1일은 월요일이며, 윤년 규칙은 기존과 동일하게 4년(윤년), 100년(평년), 400년(윤년)의 구분자를 갖는다.

 * 윤년 규칙에 따라 1900년 2월은 평년으로 28일이다.


1. 계산을 시작하는 해의 1월 1일의 요일을 구한다.

 * 시작하는 해의 1월 1일이 일요일인 경우 반환값에 이것이 누락되지 않도록 해야 한다.

2. 각 월에 해당하는 날짜만큼을 더한 후 요일을 구하여 일요일이면 반환값에 +1을 한다.

 * 2월인 경우에는 % 4, % 100, % 400 에 대한 처리를 하여 요일을 구한다.

3. 구한 결과값을 반환한다.




728x90

'공부 > 문제풀기' 카테고리의 다른 글

백준 15740 - A+B - 9  (0) 2019.10.11
백준 10953 - A+B - 6  (0) 2019.10.11
백준 2558 - A+B - 2  (0) 2019.09.24
백준 2156 - 포도주 시식  (0) 2019.08.26
백준 10844 - 쉬운 계단 수  (0) 2019.08.26
Posted by 아야카
2019. 6. 2. 16:07
728x90

Number letter counts

Problem 17

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?


NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.

1~1000을 영어로 작성했을 때의 글자 개수를 구하는 문제. 단, 띄어쓰기, 하이픈( - )은 집계에서 제외한다.

영어의 경우 글자의 구분은 다음과 같이 이루어진다.

1~19 - 각각 고유 명칭이 있으므로 해당 명칭으로 처리.
20~99 - 십의 자리 + 일의 자리. 단, 일의 자리가 0일 경우에는 생략.
100~999은 1~9 + hundred + 1~99

1000은 1 + thousand
...

각 명칭에 해당하는 글자 수를 결과 변수에 더해주면 된다.



728x90

'공부 > 문제풀기' 카테고리의 다른 글

백준 10718 - We love kriii  (0) 2019.07.20
백준 2557 - Hello World  (0) 2019.07.20
프로젝트 오일러 문제 16  (0) 2019.06.02
프로젝트 오일러 문제 15  (0) 2019.06.01
프로젝트 오일러 문제 14  (0) 2019.01.05
Posted by 아야카
2019. 6. 2. 15:07
728x90

Power digit sum

Problem 16

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?


2의 1000제곱의 각 자리 수를 모두 더할 경우 몇이 되는지 구하는 문제.
1. 필요한 만큼 배열을 할당한다. 
2. 아래에 기술한 내용을 지수만큼 반복한다.
 - 배열 각 요소에 2를 곱한다.
 - 값이 10 이상인 요소는 다음 자리에 10을 나눈 몫을 더해주고 나머지만 남긴다.
3. 배열에 있는 각 요소의 값을 모두 더한다.



728x90

'공부 > 문제풀기' 카테고리의 다른 글

백준 2557 - Hello World  (0) 2019.07.20
프로젝트 오일러 문제 17  (0) 2019.06.02
프로젝트 오일러 문제 15  (0) 2019.06.01
프로젝트 오일러 문제 14  (0) 2019.01.05
프로젝트 오일러 문제 13  (0) 2018.12.23
Posted by 아야카
2019. 6. 1. 10:11
728x90

Lattice paths

Problem 15

Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

How many such routes are there through a 20×20 grid?

20×20크기의 격자에서 왼쪽 위 시작 점부터 오른쪽 아래 끝 점까지 도달 할 수 있는 경로의 수를 구하기.
목표 지점의 왼쪽까지 갈 수 있는 경로와 위쪽까지 갈 수 있는 경로의 합으로 답을 구할 수 있다.
문제에서는 격자의 크기를 면의 수로 표현하고 있지만 실제 처리는 모서리를 기준으로 하므로 1칸 더 크게 계산한다.

1

1

1

1

2

3

1

3

6



728x90

'공부 > 문제풀기' 카테고리의 다른 글

프로젝트 오일러 문제 17  (0) 2019.06.02
프로젝트 오일러 문제 16  (0) 2019.06.02
프로젝트 오일러 문제 14  (0) 2019.01.05
프로젝트 오일러 문제 13  (0) 2018.12.23
프로젝트 오일러 문제 12  (0) 2018.11.24
Posted by 아야카
2019. 1. 5. 06:08
728x90

Longest Collatz sequence

Problem 14

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 thought that all starting numbers finish at 1.

Which starting number, under one million, produces the longest chain?

NOTE: Once the chain starts the terms are allowed to go above one million.

어떠한 수 n에 대해 콜라츠 추측을 거치는 횟수는 동일하다. 그리고 수의 범위는 100만. 
문제 풀이의 목적은 어디까지나 횟수를 구하는 것이므로 각 수에 대한 콜타츠 추측 횟수를 기록하면 된다. 
예를들어 arrNum 배열이 있다고 할 때 

arrNum[2]는 2 -> 1로 1회.
arrNum[3]는 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2로 6회를 거치고 2는 체인이 1회므로 3의 체인은 7회.
arrNum[6]은 6 -> 3으로 1회를 거치고, 3은 체인이 7회이므로 6의 체인은 8회

이와 같은 방식으로 진행하면 100만까지의 모든 수에 대한 콜라츠 추측을 빠르게 구할 수 있다.
재귀함수를 이용한다면 arrNum[3]의 과정에서 3, 10, 5, 16, 8, 4의 체인 값을 바로 파악할 수 있어 연산 시간을 조금 더 줄일 수 있게 된다.



728x90

'공부 > 문제풀기' 카테고리의 다른 글

프로젝트 오일러 문제 16  (0) 2019.06.02
프로젝트 오일러 문제 15  (0) 2019.06.01
프로젝트 오일러 문제 13  (0) 2018.12.23
프로젝트 오일러 문제 12  (0) 2018.11.24
프로젝트 오일러 문제 11  (0) 2018.11.18
Posted by 아야카
2018. 12. 23. 20:42
728x90

Large sum

Problem 13

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.


50자리 수 100개를 모두 더했을 때의 앞의 열자리 수 구하기 문제.

파이썬 같은 언어에서는 그냥 변수를 모두 더해줘서 앞의 10개만 읽어주면 되지만 C++에서는 일반적인 변수에서는 그리할 수 없으므로 별도의 방법을 모색해야 한다.



728x90

'공부 > 문제풀기' 카테고리의 다른 글

프로젝트 오일러 문제 15  (0) 2019.06.01
프로젝트 오일러 문제 14  (0) 2019.01.05
프로젝트 오일러 문제 12  (0) 2018.11.24
프로젝트 오일러 문제 11  (0) 2018.11.18
프로젝트 오일러 문제 10  (0) 2018.11.12
Posted by 아야카
2018. 11. 24. 19:33
728x90

Highly divisible triangular number

Problem 12

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,28

We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

약수의 개수가 500개 이상인 최초의 정수는 무엇인지 구하는 문제.



728x90

'공부 > 문제풀기' 카테고리의 다른 글

프로젝트 오일러 문제 14  (0) 2019.01.05
프로젝트 오일러 문제 13  (0) 2018.12.23
프로젝트 오일러 문제 11  (0) 2018.11.18
프로젝트 오일러 문제 10  (0) 2018.11.12
프로젝트 오일러 문제 9  (0) 2018.11.12
Posted by 아야카
2018. 11. 18. 23:14
728x90

Largest product in a grid

Problem 11

In the 20×20 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 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48

The product of these numbers is 26 × 63 × 78 × 14 = 1788696.

What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?

20x20 격자 속에서 한 방향으로 4개 연속 이어진 수의 곱이 가장 큰 수는 무엇인가.

8방향 탐색에 대해 묻는 문제다. 다만 곱셈을 구하는 문제이므로 4방향만 탐색해도 된다. 또, 연속된 4개의 수가 필요하므로 탐색범위는 0~19가 아닌 0~16으로 조정된다.


728x90

'공부 > 문제풀기' 카테고리의 다른 글

프로젝트 오일러 문제 13  (0) 2018.12.23
프로젝트 오일러 문제 12  (0) 2018.11.24
프로젝트 오일러 문제 10  (0) 2018.11.12
프로젝트 오일러 문제 9  (0) 2018.11.12
프로젝트 오일러 문제 8  (0) 2018.11.11
Posted by 아야카