The first place of 2^n

Problem Description
LMY and YY are mathematics and number theory lovers. They like to find and solve interesting mathematic problems together. One day LMY calculates 2n one by one, n=0, 1, 2,… and writes the results on a sheet of paper: 1,2,4,8,16,32,64,128,256,512,1024,……



LMY discovers that for every consecutive 3 or 4 results, there must be one among them whose first digit is 1, and comes to the conclusion that the first digit of 2n isn’t evenly distributed between 1 and 9, and the number of 1s exceeds those of others. YY now
intends to use statistics to prove LMY’s discovery.
 
Input
Input consists of one or more lines, each line describing one test case: an integer N, where 0≤N≤10000.



End of input is indicated by a line consisting of -1.
 
Output
For each test case, output a single line. Each line contains nine integers. The ith integer represents the number of js satisfying the condition that 2j begins with i (0≤j≤N).
 
Sample Input
  1. 0
  2. 1
  3. 3
  4. 10
  5. -1
 
Sample Output
  1. 1 0 0 0 0 0 0 0 0
  2. 1 1 0 0 0 0 0 0 0
  3. 1 1 0 1 0 0 0 1 0
  4. 4 2 1 1 1 1 0 1 0
 
Source
 
Recommend
zhuweicong   |   We have carefully selected several similar problems for you:  3219 3217 3212 3218 3216 
 

题目大意“:

妈呀,这是我们大东华09年出的题啊,好厉害,事实上是好水啊。

题目大意就是计算2^0到2^n这n个数首位为1的次数,2的次数,...9的次数。

解题思路:

我是不会告诉你log10一下就会找到你想要的东西的。

解题代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. const int maxn=10010;
  7. const double lg2=log10(2.0);
  8. int a[maxn];
  9.  
  10. void ini(){
  11. a[0]=1,a[1]=2,a[2]=4,a[3]=8;
  12. for(int i=4;i<maxn;i++){
  13. double x=i*lg2-int(i*lg2+1e-7);
  14. a[i]=pow(10.0,x);
  15. }
  16. //for(int i=0;i<20;i++) cout<<"2^"<<i<<" :"<<a[i]<<endl;
  17. }
  18.  
  19. int main(){
  20. ini();
  21. int n;
  22. while(scanf("%d",&n)!=EOF && n!=-1){
  23. int cnt[10]={0};
  24. for(int i=0;i<=n;i++){
  25. cnt[a[i]]++;
  26. }
  27. printf("%d",cnt[1]);
  28. for(int i=2;i<=9;i++){
  29. printf(" %d",cnt[i]);
  30. }
  31. printf("\n");
  32. }
  33. return 0;
  34. }

HDU 3215 The first place of 2^n (数论-水题)的更多相关文章

  1. hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0

    H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  2. HDU 1576 A/B 数论水题

    http://acm.hdu.edu.cn/showproblem.php?pid=1576 写了个ex_gcd的模板...太蠢导致推了很久的公式 这里推导一下: 因为 1 = BX + 9973Y ...

  3. HDU - 4788 Hard Disk Drive (成都邀请赛H 水题)

    HDU - 4788 Hard Disk Drive Time Limit:1000MS   Memory Limit:32768KB   64bit IO Format:%I64d & %I ...

  4. hdu 4524 郑厂长系列故事——逃离迷宫 小水题

    郑厂长系列故事——逃离迷宫 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To ...

  5. hdu 5038 (2014北京网络赛G 排序水题)

    题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题 ...

  6. hdu 2553:N皇后问题(DFS遍历,水题)

    N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. HDU 4662 MU Puzzle (2013多校6 1008 水题)

    MU Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  8. HDU 4639 Hehe (2013多校4 1008 水题)

    Hehe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)

    6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...

随机推荐

  1. docker网络访问

    一 docker网络访问 描述: 在启动容器的时候,如果不指定对应的参数,在容器外部是无法通过网络来访问容器内的网络应用和服务的.当容器中运行一些网络应用,要让外部访问这些应用时,可以通过-P或者-p ...

  2. 绝对定位等html结构,水平居中的处理方案

    1.父子结构,父relative,子absolute.子元素要水平居中:left:50%:margin-left:子元素一半的宽度.因为定位的left是按左边框开始计算.[固定问题的模块化解决]

  3. 【习题 6-4 UVA-439】Knight Moves

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs模板题 [代码] /* 1.Shoud it use long long ? 2.Have you ever test sev ...

  4. 从大整数乘法的实现到 Karatsuba 快速算法

    Karatsuba 快速乘积算法是具有独特合并过程(combine/merge)的分治算法(Karatsuba 是俄罗斯人).此算法主要是对两个整数进行相乘,并不适用于低位数(如 int 的 32 位 ...

  5. 1.4 Python基础知识 - 代码书写格式及条件判断"if ... else ..."

    一.代码的书写规则 在所有的开发语言中,代码之间都是有关联的关系,有的是包含关系,有的是上下级关系,有的是代表语句的结束.在python中也是有相应的规则的: 1.在没有上下级关系的代码中,代码要顶行 ...

  6. JS错误记录 - 取消事件冒泡、按钮、回车、ctrl回车提交留言

    window.onload = function () { var oDiv = document.getElementById('div1'); var oBtn = document.getEle ...

  7. JSF教程(11)——生命周期之Invoke Application Phase

    在这个阶段JSF实现将处理不论什么应用界别的事件,比如表单的提交或者链接点击后跳转到还有一个页面. 这时假设应用须要重定向不同 的web应用字眼或者产生一个资源其并不喊不论什么的JSF组件,那么就调用 ...

  8. 一起talk C栗子吧(第八回:C语言实例--素数)

    各位看官们,大家好,从今天開始.我们讲大型章回体科技小说 :C栗子,也就是C语言实例. 闲话休提, 言归正转. 让我们一起talk C栗子吧! 看官们.上一回中咱们说的是进制转换的样例,这一回咱们说的 ...

  9. UVA 11280 - Flying to Fredericton SPFA变形

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&c ...

  10. Web网站架构演变—高并发、大数据

    转 Web网站架构演变—高并发.大数据 2018年07月25日 17:27:22 gis_morningsun 阅读数:599   前言 我们以javaweb为例,来搭建一个简单的电商系统,看看这个系 ...