B. Magic Forest
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 ≤ 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
inputCopy
6
output
1
inputCopy
10
output
2
Note
The only xorangle in the first sample is (3, 5, 6).
题意:
给出你一个n,问有多少个最长边长小于n,并且a^b^c==0.
思路:
很明显我们只需要枚举边a,b就能得到边c,再判断一下就行。
code:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
int n,a,b,c;
while(cin>>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<i+j&&k-i<j&&k-j<i&&k<=n)
ans++;
}
cout<<ans<<endl;
}
return 0;
}