【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)

题干:

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

题目大意:

问你有多少个非严格递增的三个数a,b,c,满足a^b^c=0.

解题报告:

    这题因为异或的性质,a^a=0,0^c=c。所以在三元组中,枚举前两小的值,那么第三个值其实就已知了。也就是这三个值一定是a  ,  b  ,  a^b。然后把题目那些条件带进去做判断就可以了

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int n;
int main()
{cin>>n;ll ans = 0;for(int i = 1; i<=n; i++) {for(int j = i; j<=n; j++) {if((i^j)<=n &&(i^j)>=j&&(i+j) > (i^j)) {//printf("%d %d\n",i,j);ans++;}}}printf("%lld\n",ans);return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441120.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java生产者消费者代码_Java实现Kafka生产者消费者代码实例

Kafka的结构与RabbitMQ类似&#xff0c;消息生产者向Kafka服务器发送消息&#xff0c;Kafka接收消息后&#xff0c;再投递给消费者。生产者的消费会被发送到Topic中&#xff0c;Topic中保存着各类数据&#xff0c;每一条数据都使用键、值进行保存。每一个Topic中都包含一个或多…

【CodeForces - 304B】Calendar (前缀和,水题)

题干&#xff1a; Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendars scheme of le…

java 刷新jtextarea_Java JTextArea不能实时刷新的问题

相信JTextArea用法都了解吧&#xff0c;JTextArea textArea new JTextArea();生成一块空白的区域&#xff0c; 我的需求就是点击发送邮件按钮后&#xff0c;后台的执行日志能输出到textArea中。但是我点击发送按钮的时候&#xff0c;由于邮件的附件要好久&#xff0c;界面一直…

【CodeForces - 312C】The Closest Pair (思维)

题干&#xff1a; Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Excee…

【牛客 - 272A】Phrase String(构造,水题)

题干&#xff1a; 给出v, k&#xff0c;请你找到最小的正整数n&#xff0c;满足&#xff1a; n的二进制表示下存在一个长度为v的回文串&#xff0c;该回文串首尾都是1且n的二进制表示中至少有k个1。保证v,k均为偶数&#xff01; 由于n可能很大&#xff0c;你只需要输出对取模的…

【HDU - 1025】Constructing Roads In JGShining's Kingdom(dp最长上升子序列模型 + 二分优化)

题干&#xff1a; Constructing Roads In JGShinings Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29933 Accepted Submission(s): 8496 Problem Description JGShinings kingdom consists of 2n…

【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】小乐乐吃糖豆 (fIb博弈)

题干&#xff1a; 小乐乐是一个比较喜欢吃糖豆的小孩子&#xff0c;小乐乐的哥哥大乐乐也同样爱吃糖豆。 作为一个小孩子&#xff0c;他们永远觉得谁吃掉了最后一个糖豆&#xff0c;谁吃的糖豆最多。 为了公平起见小乐乐与大乐乐商量吃糖豆的规则如下&#xff1a; 1. …

【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】小乐乐切割方块(思维,水题)

题干&#xff1a; 小乐乐的作业本是2n*2n的方格本。 某天小乐乐的童鞋&#xff0c;想要考验一下小乐乐。 他将小乐乐的一张方格纸中的某个格子(x,y)涂成黑色&#xff0c; 小乐乐能否在将4*4的方格本沿着方格边缘且切割线与黑色方格不存在公共交点的情况下将方格本切割成两…

java web svn_如何搭建svnadmin,一个简单的svnWEB页面

Svn Admin是一个Java开发的管理Svn服务器的项目用户的web应用。安装好Svn服务器端好&#xff0c;把Svn Admin部署好&#xff0c;就可以通过web浏览器管理Svn的项目&#xff0c;管理项目的用户&#xff0c;管理项目的权限。使得管理配置Svn简便&#xff0c;再也不需要每次都到服…

java 递归 时间复杂度_递归到底是怎么实现的?它的时间复杂度怎么算?

递归到底是个啥&#xff1f;常听见的一句话就是&#xff1a;自己调用自己。按照这个说法&#xff0c;写个简单的递归自己推导一下的确可以&#xff0c;但是总是有点绕&#xff0c;推着推着自己把自己陷进去了。递归函数运行时&#xff0c;实际上会进行一个压栈(思考栈的特点&am…

Java 重定向 无法写入_java IO 文件读入,写入,重定向

Java代码 packagestar20110526;importjava.io.BufferedInputStream;importjava.io.BufferedOutputStream;importjava.io.BufferedReader;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io…

【CodeForces - 298C】Parity Game (思维,有坑)

题干&#xff1a; You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and &q…

java中能构成循环的语句_《编程导论(Java)#183;3.2.4 循环语句》

本文全然复制《编程导论(Java)3.2.4 循环语句》的内容。除【】中的说明文字。请阅读和比較其它编程教材。我知道。假设我是一个刚開始学习的人&#xff0c;《编程导论(Java)》非常不适合自学。建议同学们阅读时&#xff0c;一定选择一本其它的书同一时候看&#xff0c;或上网。…

*【CodeForces - 1088 ABC】套题比赛,A水题B模拟C构造D交互

A. Input The only line contains the integer xx (1≤x≤100)(1≤x≤100). Output You should output two integers aa and bb, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (wit…

算法讲解 -- 区间dp经典模型与优化(石子归并)

石子合并问题是最经典的DP问题。首先它有如下3种题型&#xff1a; PPT讲解&#xff1a;点击打开链接 (1)有N堆石子&#xff0c;现要将石子有序的合并成一堆&#xff0c;规定如下&#xff1a;每次只能移动任意的2堆石子合并&#xff0c;合并花费为新合成的一堆石子的数量。求将…

cpu影响matlab仿真速度吗,Proteus仿真速度很慢的分析

类型&#xff1a;行业软件大小&#xff1a;1.1M语言&#xff1a;中文 评分&#xff1a;6.5标签&#xff1a;立即下载这篇文章是我的个人实践经验&#xff1a;很多朋友在做Proteus硬件仿真的时候可能都碰上了仿真速度慢的问题&#xff0c;在点击了开始仿真之后&#xff0c;CPU过…

mysql 7天自动拒单功能,mysql查询最近7天的数据,没有数据自动补0

select DATE( createtime) date , createtime, count(1) as count from order表 where DATEDIFF( now(), createtime)<7group by date ;12 月九号没有;给他在关联一张日期的表;--生成从今天开始完整的7天日期DECLARE LastSevenDaytable(day date)DECLARE StartDaydate …

基于维纳滤波的语音增强算法 matlab,基于维纳滤波语音增强算法的改进实现

通过对维纳滤波的介绍,实现了基本维纳滤波效果;利用两级维纳滤波和两级滤波器组滤波方法实现了语音增强,达到了良好的效果。维普资讯 http://doc.docsou.com文章编号&#xff1a;0 2 8 8 (o 7 0 - 0 4 0 10—6 4 2 o )1 0 4 - 3基于维纳滤波语音增强算法的改进实现白文雅&#…

php7 获取文件类型,太简单了!PHP获取文件扩展名的7中方法

PHP中获取文件扩展名的方法第一种&#xff1a;$file x.y.z.png;echo substr(strrchr($file, .), 1);解析&#xff1a;strrchr($file, .)strrchr() 函数查找字符串在另一个字符串中最后一次出现的位置&#xff0c;并返回从该位置到字符串结尾的所有字符第二种&#xff1a;$file…

【EOJ Monthly 2018.12 - A,B,C】套题训练,部分题解

A. 题干&#xff1a; A. 仰望星空 单测试点时限: 2.0 秒 内存限制: 512 MB 你就这样静坐在草地上&#xff0c;离我稍远的地方。 我用眼角瞅着你&#xff0c;你什么话也别说。 语言是误会的根源。 但是&#xff0c;每天&#xff0c;你可以坐得离我近一些…… 你和她一起仰头…