Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3.  
  4. public class Solution {
  5. public static void main(String[] args) {
  6. try (Scanner sc = new Scanner(System.in)) {
  7. int MaxN = sc.nextInt();
  8. long maxNumber = sc.nextLong();
  9. int bigNumbers = 0;
  10. ArrayList<Long[]> combinations = new ArrayList<>();
  11. for(int n = 0; n <= MaxN; n++) {
  12. Long[] list = new Long[n + 1];
  13. list[0] = list[n] = Long.valueOf(1);
  14. combinations.add(list);
  15. }
  16. for(int n = 1; n <= MaxN; n++) {
  17. for(int k = 1; k < n; k++) {
  18. long sum = combinations.get(n - 1)[k - 1] + combinations.get(n - 1)[k];
  19. if(sum > maxNumber) {
  20. sum = maxNumber + 1;
  21. bigNumbers++;
  22. }
  23. combinations.get(n)[k] = sum;
  24. }
  25. }
  26. System.out.println(bigNumbers);
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement