Exclusive or

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 327    Accepted Submission(s): 137

Problem Description
Given n, find the value of 






Note: ⊕ denotes bitwise exclusive-or.
 
Input
The input consists of several tests. For each tests:



A single integer n (2≤n<10500).
 
Output
For each tests:



A single integer, the value of the sum.
 
Sample Input
3
4
 
Sample Output
6
4
 
Author
Xiaoxu Guo (ftiasch)
 
Source
 

题解:

以下是官方给的答案:

鉴于比較难以理解官方大神的解说,这里我研究了一下,以下给出求解化简过程:

图片有些不清晰,凑合看吧 T^T

代码:

import java.util.*;
import java.io.*;
import java.math.*; public class Main { public static BigInteger zero=BigInteger.valueOf(0);
public static BigInteger one=BigInteger.valueOf(1);
public static BigInteger two=BigInteger.valueOf(2);
public static BigInteger four=BigInteger.valueOf(4);
public static BigInteger six=BigInteger.valueOf(6); public static HashMap<BigInteger,BigInteger> map=new HashMap<BigInteger,BigInteger>(); public static BigInteger solve(BigInteger n)
{
if(map.containsKey(n))
return map.get(n);
BigInteger t=BigInteger.valueOf(0);
BigInteger k=n.divide(two);
BigInteger r=n.mod(two); if(r.compareTo(one)==0)
t=solve(k).multiply(four).add(k.multiply(six));
else {
t=two.multiply(solve(k));
t=t.add(two.multiply(solve(k.subtract(one))));
t=t.add(four.multiply(k));
t=t.subtract(four);
}
map.put(n, t);
return t;
} public static void main(String []args)
{
BigInteger n;
map.put(zero, zero);
map.put(one,zero);
Scanner cin = new Scanner(System.in);
while(cin.hasNext())
{
n=cin.nextBigInteger();
System.out.println(solve(n));
}
}
}
/*
借鉴别人的代码,学习了一下java大数和HashMap的使用方法,能够当作模版来使用了。 *转载请注明出处,谢谢。
*/

hdu 4919 Exclusive or的更多相关文章

  1. HDU 4919 Exclusive or (数论 or 打表找规律)

    Exclusive or 题目链接: http://acm.hust.edu.cn/vjudge/contest/121336#problem/J Description Given n, find ...

  2. [JAVA]HDU 4919 Exclusive or

    题意很简单, 就是给个n, 算下面这个式子的值. $\sum\limits_{i=1}^{n-1} i \otimes (n-i)$ 重点是n的范围:2≤n<10500 比赛的时候 OEIS一下 ...

  3. HDU 4919 Exclusive or 数学

    题意: 定义 \[f(n)=\sum\limits_{i=1}^{n-1}(i\oplus (n-i))\] 求\(f(n),n \leq 10^{500}\) 分析: 这个数列对应OEIS的A006 ...

  4. HDU 4919 打表找规律 java睑板 map 递归

    == oeis: 点击打开链接 瞎了,x.mod(BigInteger.ValueOf(2)).equal( BigInteger.ValueOf(1)) 写成了 x.mod(BigInteger.V ...

  5. 多校第五场 归并排序+暴力矩阵乘+模拟+java大数&amp;记忆化递归

    HDU 4911 Inversion 考点:归并排序 思路:这题呀比赛的时候忘了知道能够用归并排序算出逆序数,可是忘了归并排序的实质了.然后不会做-- 由于看到题上说是相邻的两个数才干交换的时候.感觉 ...

  6. HDU 1710 二叉树的遍历 Binary Tree Traversals

    Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  7. HDU 4069 Squiggly Sudoku(DLX)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4069 Problem Description Today we play a squiggly sud ...

  8. hdu 4915 Parenthese sequence--2014 Multi-University Training Contest 5

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 Parenthese sequence Time Limit: 2000/1000 MS (Ja ...

  9. hdu 5008 查找字典序第k小的子串

    Boring String Problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

随机推荐

  1. C++学习笔记33 转换操作符

    有时候,我们要转换为类类型和类类型,同时,这两个类继承关系不存在,这时候我们就需要一些所谓的转换操作符运营商. 一个简单的例子.类别A转换为int种类 #include <iostream> ...

  2. 区间第K大

    protected static int partitions(List<KDNode> data,int left,int right,int k,int pos){ int l = l ...

  3. 如何将IPhone应用软件发布到App Store的

    转自:http://www.shtion.com/667.html 怎样将IPhone应用程序软件公布到应用程序商店? 2009年10月19日公布 分类: App store, iphone, 手机应 ...

  4. 02、Unicode 汉子转码小工具

    原文:02.Unicode 汉子转码小工具 在做 Windows app 的时候,与服务器端交互使用的是 json 格式的数据,里面的汉字内容被 编码成 unicode 格式,在调试的时候不太方便,就 ...

  5. Lua相关的知识

    http://stackoverflow.com/questions/5438751/how-to-debug-lua-remotely http://cn.bing.com/search?q=org ...

  6. hive RegexSerDe View

    EXTERNALkeyword它允许用户创建一个外部表.在表中的同时施工指定的路径中的实际数据(LOCATION).Hive 创建内部表时.会将数据移动到数据仓库指向的路径:若创建外部表,仅记录数据所 ...

  7. Unity3d该物业(Attributes)整理

    http://blog.sina.com.cn/s/blog_5b6cb9500101857b.html Attributes属性属于U3D的RunTimeClass,所以加上下面的命名空间是必须的了 ...

  8. Winform WebBrowser引用IE版本问题

    做了一个Winform的项目.项目里使用了WebBrowser控件.以前一直都以为WebBrowser是直接调用的系统自带的IE,IE是呈现出什么样的页面WebBrowser就呈现出什么样的页面.其实 ...

  9. Source insight 3572安装和版本号An invalid source insight serial number was detected解

    Source insight最新版本3572 下载链接:http://www.sourceinsight.com/down35.html,   http://www.sourceinsight.com ...

  10. 《Javascript权威指南》13号学习笔记:使用日期和时间

    一.创Date示例 1.Date类的方法和属性是非常不静,故,申请书Date属性和方法之前.必须创建Date类的实例. var date = new Date();  //以当前日期和时间创建实例. ...