Advertisement
knyazer

Untitled

Apr 22nd, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static int algo(int len, int base, int lastres, int index, boolean isLastZero) {
  8. if (index == len) return lastres;
  9.  
  10. if (isLastZero) return algo(len, base, lastres * (base - 1), index + 1, false);
  11. else return algo(len, base, lastres * (base - 1), index + 1, false) + algo(len, base, lastres, index + 1, true);
  12.  
  13. }
  14.  
  15. public static void main(String[] args) {
  16. Scanner in = new Scanner(System.in);
  17.  
  18. int N = in.nextInt(), K = in.nextInt();
  19.  
  20. System.out.println(algo(N, K, 1, 0, true));
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement