알고리즘/SWEA 문제풀이

SWEA2019 - D1) 더블더블

당글공주 2020. 7. 22. 05:40

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QDEX6AqwDFAUq&categoryId=AV5QDEX6AqwDFAUq&categoryType=CODE

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

1부터 주어진 횟수까지 2를 곱한 값(들)을 출력하시오.

주어질 숫자는 30을 넘지 않는다.

 

input : 8

output : 1 2 4 8 16 32 64 128 256

 

==> input값까지의 2의 n 승을 구하는 문제임.

==> Math.pow 함수를 이용. 2의 n승 반복.

 

class Solution
{

       public static void main(String args[]) throws Exception
       {

              Scanner sc  = new Scanner(System.in);

              int T; 

              T=sc.nextInt();
             for(int i=0;i<=T;i++)System.out.print((int)Math.pow(2,i))+" " );

       }

}