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. Red Gate系列之二 SQL Source Control 3.0.13.4214 Edition 数据库版本控制器 完全破解+使用教程

    原文:Red Gate系列之二 SQL Source Control 3.0.13.4214 Edition 数据库版本控制器 完全破解+使用教程 Red Gate系列之二 SQL Source Co ...

  2. C#依据进程名称获取进程的句柄?

    C#依据进程名称获取进程的句柄或C#怎样获取其它进程的句柄? 有时候标题名是动态变化的,所以不使用FindWindow方法! [StructLayout(LayoutKind.Sequential)] ...

  3. Linux学习笔记——例说makefile 头文件查找路径

    0.前言     从学习C语言開始就慢慢開始接触makefile,查阅了非常多的makefile的资料但总感觉没有真正掌握makefile,假设自己动手写一个makefile总认为非常吃力.所以特意借 ...

  4. 懒人模式Singleton模式Meyers版本号

    直接看代码: /* Singleton模式保证:在一个程序,,一个类有且只有一个实例.并提供一个访问 它的全局访问点 在编程其中.很多情况下,需要确保有一类的一个实例 比如: windopws系统中仅 ...

  5. 源代码分析:LayoutParams的wrap_content, match_parent, 而详细的价值观

    问题: 慢慢地熟悉android 的过程中.发现view 要么layout初始化,建或者生产活动是很清楚.被添加到父控制,然后开始了相应的生命周期.但父控件的整个界面.还是第一个系统view. 怎么来 ...

  6. 【原创】纯OO:从设计到编码写一个FlappyBird (四)

    第三部分请点这里 这里来实现Obstacle类.其实flappybird的本质就是小鸟原地掉,然后几根柱子在走.这也是在Game类里,用obs.move()来实现游戏逻辑的原因. 我们首先必须确定几个 ...

  7. Android自带样式

    Android系统自带样式: android:theme="@android:style/Theme.Dialog" 将一个Activity显示为对话框模式 android:the ...

  8. android AlarmManager采用

    Android的闹钟实现机制非常easy, 仅仅须要调用AlarmManager.Set()方法将闹钟设置提交给系统,当闹钟时间到后,系统会依照我们的设定发送指定的广播消息.我们写一个广播去接收消息做 ...

  9. 关于scope_identity()与 @@IDENTITY

    原文:关于scope_identity()与 @@IDENTITY 参考:https://msdn.microsoft.com/zh-cn/library/ms190315.aspx scope_id ...

  10. C++类实现最大数的输出

    Description 判断整数的大小,输入n个数,找出最大的数并输出. Input 有多组测试实例,输入n,并输入n个数. Output 输出的最大的数,每个输出结果占一行. Sample Inpu ...