Last active
October 29, 2017 04:01
-
-
Save mizushou/ed2d1c78922a5d7cc8fef3fa69a2c0b5 to your computer and use it in GitHub Desktop.
# AtCoder Beginner Contest 076 問題文 square1001 は、電光掲示板に整数 1 が表示されているのを見ました。
彼は、電光掲示板に対して、以下の操作 A, 操作 B をすることができます。 操作 A: 電光掲示板に表示する整数を「今の電光掲示板の整数を 2 倍にしたもの」に変える。
操作 B: 電光掲示板に表示する整数を「今の電光掲示板の整数に K を足したもの」に変える。
square1001 は、操作 A, 操作 B 合計で N 回 行わなければなりません。 そのとき、N 回の操作後の、電光掲示板に書かれている整数として考えられる最小の値を求めなさい。 制約
1≤N,K≤10
入力はすべて整数である
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class AdditionAndMultiplication { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
int k = sc.nextInt(); | |
sc.close(); | |
int number = 1; | |
for(int i=0; i<n; i++){ | |
if(2*number < number+k) { | |
number = 2*number; | |
} else { | |
number = number+k; | |
} | |
}; | |
System.out.println(number); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment