题意:给定一个
N
N
,问你能找到多少个三元组,满足
1≤a≤b≤c≤N
1
≤
a
≤
b
≤
c
≤
N
且
a⊕b⊕c=0
a
⊕
b
⊕
c
=
0
思路:直接暴力即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll MAXN = 1e5;
ll qpow(ll a, ll n)
{
ll res = 1;
while (n)
{
if (n & 1)res = res*a%MOD;
a = a*a%MOD;
n >>= 1;
}
return res;
}
bool check(ll a,ll b,ll c)
{
ll cc[3]={a,b,c};
sort(cc,cc+3);
if(cc[0]+cc[1]>cc[2])return true;
else return false;
}
int main()
{
ll n;
cin>>n;
ll ans=0;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
if((i^j)<=n&&(i^j)>=j&&check(i,j,(i^j)))
{
ans++;
// cout<<i<<"--"<<j<<"-"<<(i^j)<<endl;
}
//cout<<ans<<endl;
}
}
printf("%I64d\n",ans);
}