B. Magic Forest

time limit per test 1 second

memory limit per test 256 megabytes

Problem Description

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).


解题心得:

  1. 题意是从1到n中选出三个数(可以相同),这三个数异或和为0,并且三个数可以形成一个三角形,问一共有多少中方案。
  2. n最大是2500,跑三重循环不现实,但是想想还是就明白的,三个数异或和为0,那么两个数异或起来肯定等于第三个数,这样跑双重循环就可以了。然后需要标记找过的三角形,由于异或起来的第三个数并不能确定和前两个数的大小关系,所以只能hash标记,这里就很坑了,之前选了一个233来hash,结果被卡了,想了半天才想到被卡了hash,连2333都会被卡。晕哦,最后23333过了。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7+10;
typedef long long ll;
map<ll,ll> maps;
int main(){
ll n;
ll a[5],ans=0;
scanf("%lld",&n);
for(ll i=1;i<=n;i++){
for(ll j=i+1;j<=n;j++){
ll c = i^j;//由前两个数得到第三个数
if(c > n || c < 1)//判读是否出了边界
continue;
a[0] = i;a[1] = j;a[2] = c;
sort(a,a+3);
ll temp = a[0];
temp = temp*23333+a[1];
temp = temp*23333+a[2];
if(maps[temp] == 233)
continue;
maps[temp] = 233;
if(a[0] + a[1] > a[2])//两小边之和大于第三边
ans++;
}
}
printf("%lld\n",ans);
return 0;
}

Codeforces Round #461 (Div. 2) B. Magic Forest的更多相关文章

  1. CF922 CodeForces Round #461(Div.2)

    CF922 CodeForces Round #461(Div.2) 这场比赛很晚呀 果断滚去睡了 现在来做一下 A CF922 A 翻译: 一开始有一个初始版本的玩具 每次有两种操作: 放一个初始版 ...

  2. Codeforces Round #461 (Div. 2)B-Magic Forest+位运算或优雅的暴力

    Magic Forest 题意:就是在1 ~ n中找三个值,满足三角形的要求,同时三个数的异或运算还要为0: , where  denotes the bitwise xor of integers  ...

  3. Codeforces Round #461 (Div. 2) B C D

    题目链接:http://codeforces.com/contest/922 B. Magic Forest time limit per test 1 second memory limit per ...

  4. Codeforces Round #461 (Div. 2)

    A - Cloning Toys /* 题目大意:给出两种机器,一种能将一种原件copy出额外一种原件和一个附件, 另一种可以把一种附件copy出额外两种附件,给你一个原件, 问能否恰好变出题目要求数 ...

  5. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  6. Codeforces Round #192 (Div. 1) B. Biridian Forest 暴力bfs

    B. Biridian Forest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/pr ...

  7. [Codeforces Round #192 (Div. 2)] D. Biridian Forest

    D. Biridian Forest time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算

    D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...

  9. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

随机推荐

  1. Maven的学习资料收集--(八) 构建MyBatis项目

    在这里,写一下,怎么使用Maven构建MyBatis项目. 1. 新建一个Web项目 可以参考前面的博客 2. 修改pom.xml,添加MyBatis依赖 <project xmlns=&quo ...

  2. mac-httpd

    mac 的httpd mac 自带了apache2, 但是不推荐使用, 因为它的目录在/Library/WebServer/Documents/下 使用brew install apache-http ...

  3. web小trick

    1.linux下交换文件 .index.php.swp 有时可查看源码2.当php后缀被过滤的时候可以直接对ph开头的后缀进行一个fuzz测试可以上传的文件后缀名3.curl -x 123.45.67 ...

  4. 用代码学习TreeView控件

    private void Form1_Load(object sender,EventArgs e){ //游离对象 TreeNode tn=new TreeNode("我很好") ...

  5. Sublime Text插件列表

    本文由 伯乐在线 - 艾凌风 翻译,黄利民 校稿.英文出处:ipestov.com.欢迎加入翻译组. 本文收录了作者辛苦收集的Sublime Text最佳插件,很全. 最佳的Sublime Text ...

  6. 学习笔记:MDN的HTML

    一.        HTML介绍: HTML —— 用于定义一个网页的结构的基本技术. 元素(Element):开始标记,加结束标记,加内容,等于元素. 两种重要的元素类别,块级元素和内联元素: 块级 ...

  7. agc007C - Pushing Balls(期望 等差数列)

    题意 题目链接 翻译来自神仙yyb Sol 又是一道神仙题.. 我开始的思路是枚举空位,但是还是不能做,GG 标算过于神仙,其中一些细节我也理解不了 题目给出的实际是一个首项为$d$,公差为$x$的等 ...

  8. Android studio 配置忽略

    直接在Ignored Files选项里点击+号,在弹出的对话框选择第二项,然后依次输入上面包含的 .gradle .idea build 三个文件夹目录,再选择第一项,找到local.properti ...

  9. 用log4net快速构建asp.net 异常日志

    log4net是一个非常完善的日志组件. 有着强大的可配置性. 有助于提高开发效率 .log4net是apache组织开发的日志组件, 同其姐妹log4j一样, 是一个开源项目. 可以以插件的形式应用 ...

  10. Dll注入:X86/X64 远程线程CreateRemoteThread 注入

    远线程注入原理是利用Windows 系统中CreateRemoteThread()这个API,其中第4个参数是准备运行的线程,我们可以将LoadLibrary()填入其中,这样就可以执行远程进程中的L ...