Polish mathematician Wacław Sierpiński (1882-1969) described the 2D geometric figure known as the Sierpiński triangle as part of his work on set theory in 1915. The triangle, which is really an infinite collection of points, can be constructed by the following algorithm:

  1. The initial shape is a solid triangle.

  2. Shrink the current shape to half its dimensions (both height and width), and make two more copies of it (giving three copies total).

  3. Arrange the three copies so that each touches the two others at their corners. Set the current shape to be the union of these three.

  4. Repeat from step 2.

Here is an illustration of the first few iterations:

 

iteration

0

1

2

3

4

As the iterations go to infinity, this process creates an infinite number of connected points. However, consider the case of a finite number of iterations. If the initial triangle has a circumference of 33, what is the sum of the circumferences of all (black) triangles at a given iteration? Write a program to find out not the exact circumference, but the number of decimal digits required to represent its integer portion. That is, find the number of decimal digits required to represent the largest integer that is at most as large as the circumference.

Input

Each test case is a line containing a non-negative integer 0≤n≤10000 indicating the number of iterations.

Output

For each case, display the case number followed by the number of decimal digits required to represent the integer portion of the circumference for the given number of iterations. Follow the format of the sample output.

Sample Input 1 Sample Output 1
0
1
5
10
100
Case 1: 1
Case 2: 1
Case 3: 2
Case 4: 3
Case 5: 19

 

题意:求黑色三角形周长之和的整数位位数

思路:

设f(n)当整数为n时黑色三角形的周长之和,所以

            f(0)=3

            f(1)=f(0)+1/2*f(0)=3/2*f(0)

            f(2)=f(1)+1/2*f(1)=3/2*f(1);

            f(n)=f(n-1)*3/2=*f(0)=

import java.util.*;
import java.math.*;
public class Main {

	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;int tt=0;
		while(cin.hasNext())
		{
			tt++;		
			n=cin.nextInt();
			BigInteger zi,mu,ans;
			zi = BigInteger.valueOf(3);
			mu = BigInteger.valueOf(2);
			zi = zi.pow(n+1);
			mu = mu.pow(n);
			ans = zi.divide(mu);
			int t=0;
			while(!ans.equals(BigInteger.valueOf(0)))
			{
				ans=ans.divide(BigInteger.valueOf(10));
				t++;
			}
			
			System.out.println("Case "+tt+": "+t); 
		}

	}

}