algorithm/백준
백준 3004 Java
umilove98
2021. 7. 26. 14:24
반응형
1부터 늘려가면서 결과값을 생각해보니
홀수 : (N/2+2)X(N/2+1)
짝수 : (N/2+1)X(N/2+1)
의 결과가 나오는 것을 확인할 수 있었다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine());
int result = 0;
if(n%2==0) {
result = (n/2+1)*(n/2+1);
}else {
result = (n/2+2)*(n/2+1);
}
System.out.println(result);
}
}
반응형