题干:

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

【Kattis - triangle 】Sierpiński Circumference(数学,求位数,取对数或Java)相关推荐

  1. 数学_同取对数(HDU_1060)

    m = n^n  ==>  lg(m) = lg(n^n)  ==>  lg(m) = n*lg(n)  ==>  m = 10^(n*lg(n)) 对于 10^N = 10^123 ...

  2. Sierpiński 的初等数论问题

    本文转自Matrix67的博客 原文地址:http://www.matrix67.com/blog/archives/6405 Sierpiński 的初等数论问题 波兰数学家 Wacław Sier ...

  3. 线性回归之数学:求导公式

    线性回归之数学:求导公式 1 常见函数的导数 2 导数的四则运算 3 练习 4 矩阵(向量)求导 参考链接:https://en.wikipedia.org/wiki/Matrix_calculus# ...

  4. 大数运算(6)——大数阶乘(求位数)

    对于求一个大数的阶乘的位数一般有两种方法: 第一种: lg(N!)=[lg(N*(N-1)*(N-2)*......*3*2*1)]+1 =[lgN+lg(N-1)+lg(N-2)+......+lg ...

  5. c语言 正整数 几位 逆序,c语言经典例题:正整数求位数and求顺、逆序位数

    经典例题:正整数求位数and求顺.逆序位数 题目要求: 给出一个int整形正整数,要求: 1.求出它是几位数字 2.按照逆序分别输出每位数字,例如123输出为321 3.按正序输出每位数字 分析: 一 ...

  6. 逆序输出并求位数 如12345 输出为 54321

    逆序输出并求位数 如12345 输出为 54321 逆序输出就是考察的 % (取余)和 /(求商的用法) #include "stdio.h" int main(){printf( ...

  7. r中如何求变量的对数转换_对数转换以求阳性。

    r中如何求变量的对数转换 In Simple terms, log transform squashes or compresses range of large numbers and expand ...

  8. java:数学运算的取最大、最小、绝对值的函数方法

    数学运算的取最大.最小.绝对值的函数方法 相关说明 源码 运行结果 相关说明 方法Math.A A为数学方法 数学方法: min(a,b) ········a到b的最小值 max(c,d) ····· ...

  9. php取模,PHP的求余(取模)运算

    这篇文章主要介绍了关于PHP的求余(取模)运算 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 先来看下个小案例:$n = 8.45; $result = $n*100; echo g ...

最新文章

  1. 启动 ServiceFabric Windows服务报1053
  2. centos6.5下载卸载mysql_Linux CentOS 6.5 卸载、tar安装MySQL
  3. 64 大小_电脑系统32位和64位有什么区别
  4. ScrollView(RecyclerView等)为什么会自动滚动原理分析,还有阻止自动滑动的解决方...
  5. 字节面试官:如何实现Ajax并发请求控制
  6. 前端怎么获取cookie的值_京东购物小程序cookie方案实践(附Demo)
  7. python灰度图生成g代码_Python打造一个在线G代码生成器
  8. Cloudera官方课程管理员(CCAH)、开发者(CCA175)、数据分析
  9. 数据挖掘之模糊集与模糊逻辑
  10. 对计算机科学与技术专业的认识和思考,计算机科学与技术专业的认识与思考
  11. Actor 模型是什么?Gear 为什么使用它?
  12. tebsorflow2.0 卷积神经网络的实现实例
  13. HTML期末学生大作业-视频影视网页html+css+javascript(带报告册)
  14. Verilog的时序问题和SystemVerilog TestBench激励时序
  15. 学习了罗昭锋的文献管理与信息分析的感受
  16. Java Web实用开发技术
  17. 商用短链平台_第8章_ 账号微服务注册模块+短信验证码+阿里云OSS开发实战
  18. Okidoki - Alpha阶段项目展示 - TEAM LESS ERROR
  19. ADT无法识别飞思卡尔的解决办法
  20. 【第5节 if和for】

热门文章

  1. Delphi手动创建数据集
  2. php npm,php – Laravel中NPM,Composer和Bower的区别?
  3. HTML文件可通过www进行传输,使用 zssh 进行 Zmodem 文件传输
  4. 7-3 寻找大富翁 (25 分)
  5. mysql两个表查询修改_MySQL:查询、修改(二)
  6. history模式监听_面试题:VueRouter中的 hash 模式和 history 模式有什么区别
  7. threejs向量夹角和夹角方向
  8. Linux编程练习 --多线程1--线程创建
  9. 坦克大战代码_坦克大战系列文章-坦克大战简介
  10. php hasmany,浅谈laravel orm 中的一对多关系 hasMany