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. PyQt学习笔记

    ---------------个人学习笔记--------------- 1.QtWidgets.QApplication.instance().quit() 方法可退出当前窗体 2.self.Qla ...

  2. JAVA 集合类小结

    一 集合和数组 因为本人也是个go的爱好者,所以对于集合类算是摸的比较透的. 说到集合,必须了解数组和集合. Java的数组长度固定,集合长度不定.集合是特定的数据结构的集合. 而go里面并没有集合, ...

  3. 12.Visual Studio 2013中的默认快捷键

    这篇大致是IDE的使用技巧,常用的也就那么几个. 我自己用的最多的是注释.取消注释.格式调整.运行测试.开始调试.断开调试.重新开始调试.删除行ctrl+L.保存.全部保存.打开资源管理器.搜索等几个 ...

  4. enable orgmode latex preview to support retina on mac

    Table of Contents 1. enable orgmode latex preview to support retina on mac 1.1. get the proper versi ...

  5. 快速获取雪碧图的图标样式插件 - gulp-css-spriter教程

    如何快速把合成好的雪碧图,快速获取图标的样式呢? 用gulp-css-spriter很简单. 第一步: 在某个文件夹用shitf+鼠标右键 第二步: npm install gulp-css-spri ...

  6. 海海DRM视频保护解密流程分析

    环境及工具 手机    :小米手机 MI 2A 系统版本: Android 4.1.1 工具    : IDA pro 6.6 .C32Asm .VS2005 一:第一次打开加密视频会出现如下验证: ...

  7. Spring mvc + maven + tomcat配置问题

    在用maven搭建spring mvc时候, 个人遇到过很多的问题, 现在把遇到的问题总结下: 1.  首先点击项目->Run As->Maven clean, 这一步把之前不管有没有ma ...

  8. 利用binlog2sql解析mysqlbinlog row行日志

    binlog2sql 项目作者:曹单锋 github项目地址:https://github.com/danfengcao/binlog2sql 也可在github.com上搜索“binlog2sql” ...

  9. java Vamei快速教程04 封装和接口

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 总结之前的内容,对象(object)指代某一事物,类(class)指代象的类型.对 ...

  10. 理顺react,flux,redux这些概念的关系

    作者:北溟小鱼hk链接:https://www.zhihu.com/question/47686258/answer/107209140来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...