HDU 4919 exclusive or

Source: Internet
Author: User

Question:

Calculate formula-B in the question

Ideas:

When pushing the recurrence formula, the teammates said that there was a relationship between numbers but they didn't come out.-Question B had a process:


In the process of pushing, the most clever thing is that the two adjacent numbers of the exclusive or nature are equivalent to modifying the last two digits of the binary. However, the result of this process is the same.

The number in the question is too big. It is easier to write in Java to solve recursive problems.

Code:

Import Java. util. *; import Java. io. *; import Java. math. *; public class main {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 F (biginteger N) {If (map. containskey (N) return map. get (n); biginteger tmp1 = n. divide (two); biginteger tmp2 = n. moD (two); biginteger tmp3 = tmp1.subtract (biginteger. one); If (tmp2.compareto (biginteger. one) = 0) tmp1 = f (tmp1 ). multiply (four ). add (tmp1.multiply (six); elsetmp1 = f (tmp1 ). multiply (two ). add (f (tmp3 ). multiply (two )). add (tmp1.multiply (four )). subtract (four); map. put (n, tmp1); Return tmp1;} public static void main (string [] ARGs) {program CIN = new program (system. in); map. put (biginteger. zero, biginteger. zero); map. put (biginteger. one, biginteger. zero); While (CIN. hasnext () {biginteger n = cin. nextbiginteger (); system. out. println (f (n);} cin. close ();}}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.