Official

A - 2^N Editorial by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
「競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) (https://atcoder.jp/contests/typical90) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
「C++入門 AtCoder Programming Guide for beginners (APG4b)」(https://atcoder.jp/contests/APG4b) is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.


This problem requires a calculation of powers. Many programming languages provide “pow” function that enables to calculate powers, but it often yields a floating-point-valued result, so you have to be careful of errors. As in this problem, the powers of \(2\) can be calculated with bit shifts.

Sample code (C) (Bit shift)

#include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	printf("%d\n",1<<n);
}

Sample code (C)(pow)

#include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	printf("%d\n",(int)pow(2,n));
}

Sample code (Python)

N=int(input())
print(1<<N)

Sample code (Python)

N=int(input())
print(2**N)

posted:
last update: