PS [8일차]

Daniel·2022년 7월 24일
0

PS

목록 보기
8/32
post-thumbnail

문제번호

2748

import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner (System.in);
		
		int n = in.nextInt();
		
		long Fn_2 = 0;
		long Fn_1 = 1;
	
		long result = 0;
		
		for (int i = 0 ;i < n; i++) {
			if (i == 0) {
				result = Fn_1 + Fn_2;}
			else if (i >= 1) {
				result = Fn_1 + Fn_2;
				Fn_2 = Fn_1 ;
				Fn_1 = result;
			}
		}
		System.out.println(result);
	}
}

문제

피보나치 수열 문제 + 타입을 고려해야하는 문제

풀이

https://velog.io/@juyeon10120/PS-6일차

해당 문제는 처리할수 있는 정수의 범위만 늘어난 문제이다. 풀이 알고리즘은 상단 링크를 들어가면 있다.

profile
폐쇄

0개의 댓글