망나니 AWOS의 일상
article thumbnail

간단하게 표로 설명하겠다. (공책에 끄적였으나 보기가 매우 불편합니다.)

 

오각형의 단계와 점의 개수로 표에 값을 넣어봤다. 

단계 1 2 3 4 5
점의 개수 5 5+7 5+7+10 5+7+10+13 5+7+10+13+16

표에서 보면 어떠한 규칙이 있다.

기존에 점의 개수를 두고 추가적으로 더해지는데

 

1단계 5, 2단계 7

3단계부터는 10 

4단계 13

5단계 16

 

3단계부터는 등차수열 즉, 3씩 증가한다.

 

등차수열을 생각하고 코드를 짜면 된다.

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        System.out.println(recurOctagon(N));
    }

    public static BigInteger recurOctagon(int N) {

        BigInteger firstIndex = BigInteger.valueOf(5);
        BigInteger secondIndex = BigInteger.valueOf(7);
        BigInteger addValue = BigInteger.valueOf(3);

        for(int i=2; i<=N; i++){
            firstIndex = firstIndex.add(secondIndex);
            secondIndex = secondIndex.add(addValue);
            firstIndex = firstIndex.mod(BigInteger.valueOf(45678));

        }
        return firstIndex;
    }
}

'알고리즘 > 백준' 카테고리의 다른 글

[python] 백준 3009번 네 번째 점  (0) 2021.08.15
[python] 백준 2566번 최댓값  (0) 2021.08.13
[java] 백준 2506번 점수계산  (0) 2021.08.12
[java] 백준 2501번 약수 구하기  (4) 2021.08.11
[java] 백준 1568번 새  (13) 2021.08.10
profile

망나니 AWOS의 일상

@AWOS

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!