0
点赞
收藏
分享

微信扫一扫

【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)

题干:

Imp is in a magic forest, where xorangles grow (wut?)

A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest.

Formally, for a given integer n you have to find the number of such triples (a, b, c), that:

  • 1 ≤abcn;
  • , wheredenotes the​​​bitwise xor​​ of integersxandy.
  • (a,b,c) form a non-degenerate (with strictly positive area) triangle.

Input

The only line contains a single integer n (1 ≤ n ≤ 2500).

Output

Print the number of xorangles of order n.

Examples

Input


6

Output


1

Input


10

Output


2

Note

The only xorangle in the first sample is (3, 5, 6).

题目大意:

问你有多少个非严格递增的三个数a,b,c,满足a^b^c=0.

解题报告:

    这题因为异或的性质,a^a=0,0^c=c。所以在三元组中,枚举前两小的值,那么第三个值其实就已知了。也就是这三个值一定是a  ,  b  ,  a^b。然后把题目那些条件带进去做判断就可以了

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int n;
int main()
{
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&&(i+j) > (i^j)) {
//printf("%d %d\n",i,j);
ans++;
}
}
}
printf("%lld\n",ans);

return 0 ;
}

 


举报

相关推荐

0 条评论