# | Problem | Pass Rate (passed user / total user) |
---|---|---|
12905 | GCD of Two Numbers |
|
12906 | Tower of Hanoi |
|
Description
Given two natural numbers. Please write a C program to find out what is the greatest common divisor of these two natural numbers.
Hint: Use “Euclidean algorithms” (輾轉相除法).
Input
Two integers Num1, Num2.
Note that:
- 1 <= Num1, Num2 <= 32,767.
Output
Output should follow below format:
N
Note that:
- Need to have a return value('\n') at the end of your string.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Tower of Hanoi is a mathematical puzzle where we have three rods and N disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
- Only one disk can be moved at a time.
- Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
- No disk may be placed on top of a smaller disk.
Given a integer N to represents N disks. Please write a C program to show all the steps to move all N disks from rod 'A' to rod 'C'.
Input
An integer N to represent the number of disks.
Note that:
- 1 <= N <= 16
Output
Output should follow below format:
Disk n moved from X to Y
…
Note that:
- Need to have a return value('\n') at the end of your string.
- n is the number of moving disk.
- X, Y are one of ‘A’, ‘B’, ‘C’, which represents the index of rod. ‘A’ is the first rod, ‘B’ is the second rod, and ‘C’ is the third rod.