fork download
  1. class Main
  2. {
  3. public static void main (String[] args) throws java.lang.Exception
  4. {
  5. java.util.Scanner i = new java.util.Scanner(System.in);
  6. int n = i.nextInt();
  7. int m = i.nextInt();
  8. if (m > n){
  9. int t = n;
  10. n = m;
  11. m = t;
  12. }
  13. long den = 1, ways = 1; // den - знаменатель, ways - количество способов.
  14. for (int j = 0; j < m - 1; j++) {
  15. ways *= n + j;
  16. if (ways % den == 0) {
  17. ways /= den;
  18. den++;
  19. }
  20. }
  21. System.out.println(ways);
  22. }
  23. }
Success #stdin #stdout 0.1s 35608KB
stdin
30 30
stdout
30067266499541040