Codeforces Round #461 (Div. 2) B. Magic Forest

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gtuif/article/details/82284232

B. Magic Forest

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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

input

Copy

6

output

Copy

1

input

Copy

10

output

Copy

2

Note

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

题意:问在1~n的范围内,有多少对构成三角形的边满足下列条件1 ≤ a ≤ b ≤ c ≤ n;a^b^c=0;

思路:由a^b^c=0我们可以枚举a,b;c=a^b;暴力跑一发就行了;

下面附上我的代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
bool check(int a,int b,int c){
	if(a+b>c&&a+c>b&&b+c>a&&a-b<c&&b-a<c&&a-c<b&&c-a<b&&c-b<a&&b-c<a){
		return true;
	}else{
		return false;
	}
	
}
int main()
{
	int n;
	
	scanf("%d", &n);
	int i, j;
		int num=0;
		for(i=1;i<=n;i++){
			for(j=i;j<=n;j++){
				    int k = i ^ j;
					if(check(i,j,k) && k >= j && k <=n){
							num++;
					}
				}
			}
		printf("%d\n",num);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/gtuif/article/details/82284232