Hanoi (a) time limit:MS | Memory limit:65535 KB Difficulty:3
-
Describe
-
In India, there is an old legend: in the world center of Sheng Miao (in northern India), a yellow copper plate is inserted with three stone needles. In the creation of the world, The Hindu god Brahma, on one of the needles, dressed from the bottom to the top 64 pieces of gold, the so-called Hanoi. No matter the day or night, there is always a monk in accordance with the following rules to move these gold pieces: one at a time, no matter where the needle, the small pieces must be on top of the large. The monks predicted that the world would be wiped out in a thunderbolt when all the pieces of gold were moved from the needle on which Brahma was dressed, and that the Vatican, the temples and all sentient beings would perish.
Now, can you calculate the minimum number of steps you need to move when all the Nottingham gold slices that start with M gold are moved to the other needle? (Because the result is too big, now only ask you to calculate the result of the decimal bit last six bits)
-
Input
-
The first line is an integer N representing the number of groups of test data (0<N<20)
The first line of each set of test data is an integer m, which represents the number of gold slices at the beginning. (0<m<1000000000)
-
Output
-
The output is the last six bits of the decimal representation of the minimum number of steps that need to be moved to move all the gold sheet from the starting pin to the other.
-
Sample input
-
211000
-
Sample output
-
169375
Solving: moving steps equals 2^n-1
#include <stdio.h> #include <string.h>long long f (Long long a,int b,int c) { long long Ans=1; a=a%c; while (b) { if (b&1) ans= (ans*a)%c; b/=2; A= (a*a)%c; } return ans;} int main () {int n,m,j,i,t;scanf ("%d", &t), while (t--) {scanf ("%d", &n);p rintf ("%lld\n", f (2,n,1000000)-1);} return 0;}
Nyoj 88 Hanoi (a) "Fast power"