H.cpp 351 B

12345678910111213141516
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int n, x;
  5. while (cin >> n >> x) {
  6. if (n == 0 && x == 0) break;
  7. int cnt = 0;
  8. for (int i = 1; i <= n; i++)
  9. for (int j = i + 1; j <= n; j++)
  10. for (int k = j + 1; k <= n; k++) {
  11. if (i + j + k == x) ++cnt;
  12. }
  13. cout << cnt << endl;
  14. }
  15. return 0;
  16. }