Odd Grasshopper

#include"bits/stdc++.h"
#define ll long long
using namespace std;
const int N  = 1e6+5;
ll t,n,m;
string a,b;
int main()
{
    ios::sync_with_stdio(false);
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        ll ans = m % 4;
        for(ll i=m-ans+1;i<=m;i++){
            if(abs(n)&1) n+=i;
            else n-=i;
        }
        cout << n << endl;
    }
    // 奇   --++  偶  ++--
 
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_53013914/article/details/121171678