<cf>B. Magic Forest

本文介绍了一种特殊的三角形——异或三角形,并提供了一个算法来计算特定条件下这种三角形的数量。输入一个整数n,算法将遍历所有可能的三角形组合,通过异或操作筛选出符合条件的三角形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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
6
Output
1
Input
10
Output
2
Note

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

异或三角形(应该这么叫吧 )....... >O(n^2)直接便利就好 数据2500而已

#include<iostream>
using namespace std;
typedef long long ll ;
#define f(i,l,r) for(int i=l;i<=r;++i)
#define g(i,l,r) for(int i=l;i>=r;--i)





int main(){
	int n ;
	int ans= 0;

	cin>>n;
	f(i,1,n)
		f(j,i+1,n){
			int m = i^j;   
			if(m>=1&& m <=n&&m>j&&i+m>j&&j+m>i&&i+j>m)
				ans++;
	}
	cout<<ans<<endl;
}


未来的我一定会感谢正在努力的现在的我!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值