先上题目:

Xor pairs

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
SubmitStatus

Problem Description

long long ans = 0;
for(int i = 1; i <= n; i ++)
    for(int j = i + 1; j <= n; j ++)
       for(int k = j + 1; k <= n; k ++)
           if((i ^ j ^ k) == 0) ans ++;

Input

约10000组数据,每组数据一行n (1 <= n <= 10^9)

Output

对于每组数据,输出一行,ans

Sample Input

10
11
12

Sample Output

10
13
17   第一眼看输入只有一个数字,然后就有输出,这有很大几率是找规律。
  打表以后发现好像规律还不是很明显,将相邻的两项相减,然后就找到规律了:0,1,0,1,2,3,0,1,2,3,4,5,6,7,0,``````
  然后就是构造函数了,思路是先求出距离输入的n最近的2的次幂求和的那个幂数,然后求出每一个以2的次幂-1为终结的等差数列的和,求出以后再加上多出来的那一部分等差数列,就可以得到的数了。中间可能还需要一点小的调整。 上代码:
 /*
* this code is made by sineatos
* Problem: 1183
* Verdict: Accepted
* Submission Date: 2014-07-31 14:59:31
* Time: 8MS
* Memory: 1088KB
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 100002
#define ll long long
using namespace std; int main()
{
ll n,i,c,r;
while(~scanf("%lld",&n))
{
if(n<) printf("0\n");
else if(n==) printf("1\n");
else
{
ll sum=;
c=;
for(i=; (c+i)<n; i<<=)
{
c+=i;
sum+=i*(i-)/;
}
r=n-c;
sum+=(+(r-))*(r-)/;
printf("%lld\n",sum);
}
} return ;
}

/*Xor pairs*/


ACDream - Xor pairs的更多相关文章

  1. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  2. Codeforeces 617E XOR and Favorite Number(莫队+小技巧)

    E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  3. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法

    E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...

  4. CodeForces 276D – Little Girl and Maximum XOR 贪心

    整整10个月后第二次搞这个问题才搞懂........第一次还是太随意了. 解题思路: 经过打表可得规律答案要么是0 要么是2的N次 - 1 要得到最大的XOR值,其值一定是2的N次 - 1 即在 l ...

  5. XOR and Favorite Number(莫队算法+分块)

    E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  6. uval 6657 GCD XOR

    GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 ...

  7. GCD XOR uvalive6657

    GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 ...

  8. ARC 066D Xor Sum AtCoder - 2272 (打表找规律)

    Problem Statement You are given a positive integer N. Find the number of the pairs of integers u and ...

  9. Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip dfs 按位考虑

    E. Mahmoud and a xor trip 题目连接: http://codeforces.com/contest/766/problem/E Description Mahmoud and ...

随机推荐

  1. UVALive 4671 K-neighbor substrings 巧用FFT

    UVALive4671   K-neighbor substrings   给定一个两个字符串A和B B为模式串.问A中有多少不同子串与B的距离小于k 所谓距离就是不同位的个数. 由于字符串只包含a和 ...

  2. discuz的cutstr函数

    function cutstr($string, $length, $dot = ' ...') { if(strlen($string) <= $length) { return $strin ...

  3. Windows(7/8/10)搭建kibana 6.x版本(elasticsearch的可视化服务)

    在搭建kibana之前,我们先了解下什么是kibana Kibana 是一款开源的数据分析和可视化平台,它是 Elastic Stack 成员之一,设计用于和 Elasticsearch 协作.您可以 ...

  4. datatable 的使用方法

    遍历datatable的方法 +方法一:DataTable dt = dataSet.Tables[0];for(int i = 0 ; i < dt.Rows.Count ; i++){str ...

  5. Boost(1.69.0) windows入门(译)

    目录 Boost windows入门 1. 获得Boost源代码 2. Boost源代码组织 The Boost Distribution 3. 仅用头文件的库 Header-Only Librari ...

  6. 命令框中oracle dmp文件的导入和导出(仅做个人备忘)

    1.dmp文件导出 (全部)exp 用户名/密码 rows=y indexes=n compress=n buffer=65536 feedback=100000  file=F:\test.dmp ...

  7. ACM_统计字符串

    统计字符串 Time Limit: 2000/1000ms (Java/Others) Problem Description: 给定n个字符串,统计字符串的个数. 如给定 5 sss ab sss ...

  8. Spring Boot (23) Lettuce Redis

    Spring Boot除了支持常见的ORM框架外,更是对常用的中间件提供了非常好的封装,随着SpringBoot2.x的到来,支持的组件也越来越丰富,也越来越成熟,其中对Redis的支持不仅仅是它丰富 ...

  9. Spring Cloud (5) 分布式配置中心

    Spring Cloud Config 在分布式系统中,由于服务数量很多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,使用Spring Cloud ...

  10. 将class类对象转化成json的数据格式

    直接上代码: JSONObject的的使用需要导入json-lib-2.4-jdk15.jar包,下载地址:http://mvnrepository.com/artifact/net.sf.json- ...