题干:

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

00

11

22

33

44

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≤100000≤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

 解题报告:

   推出公式发现需要求3* (1.5)^n的位数,处理方法很多,可以double存答案,然后每一次进到1e9的时候,就答案+=9,数字/=1e9,最后肯定得到了一个1e9范围以内的数字,再单独处理就行。也可以用Java的大整数类先算出分母和分子,再做除法(向下取整),然后按位处理。

   也可以直接用C++中取log的操作得到答案。整数n的位数就是log10(n) + 1.

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const double eps=1e-8;
int main()
{
	int t,q,i,j,n,cnt=0,ans;
	while(scanf("%d",&n)!=EOF){
		ans=log10(3)+n*log10(3.0/2);
		ans++;
		printf("Case %d: %d\n",++cnt,ans);
	}

	return 0;
}