fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24.  
  25. void bruteforce(int n, int m){
  26. int ways = 0;
  27. for(int i=0; i<=m; i++){
  28. for(int j=0; j<=m; j++){
  29. for(int k=0; k<=m; k++){
  30. if(i+j+k == n) ways++;
  31. }
  32. }
  33. }
  34. cout << ways << endl;
  35. }
  36. void consistency(int n, int m) {
  37. int ways = 0;
  38. for(int i=0; i<=m; i++){
  39. for(int j=0; j<=m; j++){
  40. int k = n-(i+j);
  41. if(k>=0 && k<=m) ways++;
  42. }
  43. }
  44. cout << ways << endl;
  45. }
  46.  
  47. void solve() {
  48.  
  49. int n, m;
  50. cin >> n >> m;
  51. bruteforce(n, m);
  52. consistency(n, m);
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60. int32_t main() {
  61. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  62.  
  63. int t = 1;
  64. while (t--) {
  65. solve();
  66. }
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0s 5316KB
stdin
2 2
stdout
6
6