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 ();}}