先上题目:

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. JZOJ 5791 阶乘 —— 因数

    题目:https://jzoj.net/senior/#main/show/5791 题意:有n个正整数a[i],设它们乘积为p,你可以给p乘上一个正整数q,使p*q刚好为正整数m的阶乘,求m的最小值 ...

  2. Coursera Algorithms week4 基础标签表 练习测验:Java autoboxing and equals

    1. Java autoboxing and equals(). Consider two double values a and b and their corresponding Double v ...

  3. ES6详解八:模块(Module)!--各种导入导出方法

    [-] 基本用法 命名导出named exports 默认导出 命名导出结合默认导出 仅支持静态导入导出 各种导入和导出方式总结   modules是ES6引入的最重要一个特性. 所以以后再写模块,直 ...

  4. bzoj1877 晨跑(费用流)

    1877: [SDOI2009]晨跑 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 2138  Solved: 1145 Description Elax ...

  5. H5 触摸事件

    HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事件主 ...

  6. BZOJ 4310 二分+SA+RMQ

    思路: 首先求出后缀数组和height数组,这样能得到本质不同的子串数目 这里利用:本质不同的子串=∑(Len−SA[i]−height[i])=∑(Len−SA[i]−height[i])利用SA[ ...

  7. 【知识总结】多项式全家桶(一)(NTT、加减乘除和求逆)

    我这种数学一窍不通的菜鸡终于开始学多项式全家桶了-- 必须要会的前置技能:FFT(不会?戳我:[知识总结]快速傅里叶变换(FFT)) 以下无特殊说明的情况下,多项式的长度指多项式最高次项的次数加\(1 ...

  8. Linux命令(005) -- kill、pkill和killall的比较

    kill命令用来“杀掉”指定进程PID的进程.终止一个前台进程可以使用Ctrl+C,终止一个后台进程就须用kill命令.kill命令是通过向进程发送指定的信号来结束相应进程的.在默认情况下,kill命 ...

  9. MariaDB常用命令手记

    创建用户命令 mysql>create user username@localhost identified by 'password'; 直接创建用户并授权的命令 mysql>grant ...

  10. python2升级成python3

    系统环境centos 6.5原python版本2.6.6目标python版本3.5.11.下载python3.5wget --no-check-certificate  http://www.pyth ...