Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int k = scanner.nextInt();
- int n = scanner.nextInt();
- System.out.print(calculate(k, n));
- }
- private static int calculate(int k, int n) {
- if (n == 1) {
- return k;
- }
- if (n == 2) {
- return k + 1;
- }//5
- if (n == 3) {
- return 2 * k + 1;
- }
- if (n == 4) {
- return k + 2;
- }
- if (n % 3 == 2) {
- return calculate(k, n / 3 + 1) + 1;
- } else if (n % 3 == 0) {
- return 2 * calculate(k, n - 1) - 1;
- } else {
- return calculate(k, n / 3) + 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement