Source Code
#include <cstring>
#include <vector>
#include <stdio.h>
#include <bitset>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include<sstream>
#include <iomanip>
#include <vector>
#include<utility>
#include <iostream>
#define ll long long
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t; cin >> t;
	while (t--) {
		int n, k; cin >> n >> k;
		vector<ll>v(n+1);
		ll ctr = 0;
		for (int i = 1; i <= n; i++) {
			v[i] = i;
		}
		for (int i = 1; i <= n; i++) {
			ll temp = v[i];
			v[i] = 0;
			if (k - i >= 1 && k - i <= n) {
				if (v[k - i] == k - i) {
					ctr++;
				}
				v[k - i] = 0;
			}
		}
		cout << ctr << "\n";
	}
}
Copy
Ramadan Candies makamkh899
GNU G++17
5 ms
376 KB
Wrong Answer