先上题目:

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. 一、Linux文件权限与目录配置

    行文结构如下: 用户和用户组 Linux文件权限概念 Linux目录配置 重点回顾 1.用户与用户组 Linux是个多用户.多任务的系统,可能有多人同时使用这台机器进行工作,为了考虑每个人的隐私和工作 ...

  2. E20171015-hm

    quirk   n. 怪癖; 奇事,巧合; 突然的弯曲; propagation  n. 宣传; 传播,传输,蔓延,扩展,波及深度; [生]繁殖法,[地]传导; 培养; immediate  adj. ...

  3. Rails5 Controller Document

    更新: 2017/06/28 大致完成全部 更新: 2017/06/29 补充module文件命名规则 更新: 2017/07/09 补充session的设置 更新: 2018/03/06 修正ren ...

  4. 无限极分类算法 thinkphp

    <?php/** 本类实现的是无限级递归分类的管理*/class InfiniteLevel{ public $id_str=""; public function add_ ...

  5. 自定义滚动条配合鼠标滚轮demo

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...

  6. C# 清除coockies

    if (Request.Cookies["zxcookies"] != null)        {            HttpCookie mycookie;         ...

  7. ZOJ1969-Hard to Believe, but True!

    import re while True: x = raw_input() if(x == '0+0=0'): print 'True' break a,b,c = re.split('[+=]', ...

  8. Dancing Links X 学习笔记

    \(\\\) Definitions 双向链表:记录前后两个指针的链表,每个顺序关系都有双向的指针维护. \(Dancing\ Links\):双向十字循环链表,建立在二维关系上,每个元素记录上下左右 ...

  9. 控制台——args参数的赋值方法

    args参数的赋值方法有好几种,主要介绍两种. 外部传参的方法:先找到bin目录下的exe文件,并创建快捷方法,在目标后面追加参数. 控制台主函数入口实现方法 static void Main(str ...

  10. java设计模式03装饰者者模式

    动态地给一个对象添加一些额外的职责.就增加功能来说, Decorator模式相比生成子类更为灵活.该模式以对客 户端透明的方式扩展对象的功能. (1)在不影响其他对象的情况下,以动态.透明的方式给单个 ...