先上题目:

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. jeesite ckeditor数据库 HTML 被编码 的问题解决

    public abstract class BaseController { /** * 初始化数据绑定 * 1. 将所有传递进来的String进行HTML编码,防止XSS攻击 * 2. 将字段中Da ...

  2. bzoj4563: [Haoi2016]放棋子(错排+高精)

    4563: [Haoi2016]放棋子 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 387  Solved: 247[Submit][Status] ...

  3. robotframework - 介绍&应用

    一.参考简书链接 :https://www.jianshu.com/p/c3a9d20db4e5 二.介绍 Robot Framework是一个基于Python的,可扩展的关键字驱动的测试自动化框架, ...

  4. 月薪5K和月薪50K的程序员,差距都在哪里?

    毕业两年买房买车,BAT里拼杀年薪百万.这些大神级的传说想必大家都有耳闻. 而渴望成为人生赢家的程序员们也怀揣着这样梦想,纷纷踏入互联网的大门.   假以时日,这些人的差距愈发明显.最直观的就是薪资水 ...

  5. vagrant使用centos的环境安装..

    vagrant这货挺好用的..简要就是, 下好virtualbox, vagrant, 然后下个你需要的box. 然后vagrant box add boxname boxpath就行. 然后在合适的 ...

  6. Spring-Security-OAuth2微信网页授权

    @Controller public class Controller1 { @Autowired private OAuth2ClientContext context; @Bean @Scope( ...

  7. 在Windows2003安装配置Bitvise SSH Server后,不能使用软件内建立的用户登录!

    Google:  I can only log in with an administrator account - attempting to log in with a regular accou ...

  8. (转)Vue 爬坑之路(三)—— 使用 vue-router 跳转页面

    使用 Vue.js 做项目的时候,一个页面是由多个组件构成的,所以在跳转页面的时候,并不适合用传统的 href,于是 vue-router 应运而生. 官方文档: https://router.vue ...

  9. Android O Bitmap 内存分配

      我们知道,一般认为在Android进程的内存模型中,heap分为两部分,一部分是native heap,一部分是Dalvik heap(实际上也是native heap的一部分).   Andro ...

  10. android学习之路资料集合

    版权声明:本文为 stormzhang 原创文章,可以随意转载,但必须在明确位置注明出处!!! 这篇博客背后的故事 一路走来很不容易,刚好知乎上被人邀请回答如何自学android编程, 就借这个机会在 ...