Imp is in a magic forest, where xorangles grow (wut?)
![](https://i-blog.csdnimg.cn/blog_migrate/776cfdd248382ed60533f96d5f52720f.png)
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 ≤ a ≤ b ≤ c ≤ n;
-
, where
denotes the bitwise xor of integers x and y.
- (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).
题意:
在1到n内取3个数a,b ,c满足以下有条件
条件1:1<=a<=b<=c<=n
条件2:a^b^c=0;
条件3:构成三角形
思路:x与本身的异或为0
代码:
#include<stdio.h>
#include<string.h>
using namespace std;
int cheak(int a,int b,int c){ //判断三角形
return a+b>c&&c-b<a;
}
int main(){
int n;
scanf("%d",&n);
int ans=0;
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++){
int k=i^j;
if(k>=j&&k<=n){
ans+=cheak(i,j,k);
}
}
printf("%d\n",ans);
return 0;
}