Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static int algo(int len, int base, int lastres, int index, boolean isLastZero) {
- if (index == len) return lastres;
- if (isLastZero) return algo(len, base, lastres * (base - 1), index + 1, false);
- else return algo(len, base, lastres * (base - 1), index + 1, false) + algo(len, base, lastres, index + 1, true);
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int N = in.nextInt(), K = in.nextInt();
- System.out.println(algo(N, K, 1, 0, true));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement