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
0
1
3
10
-1
 
Sample Output
1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
1 1 0 1 0 0 0 1 0
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一下就会找到你想要的东西的。

解题代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; const int maxn=10010;
const double lg2=log10(2.0);
int a[maxn]; void ini(){
a[0]=1,a[1]=2,a[2]=4,a[3]=8;
for(int i=4;i<maxn;i++){
double x=i*lg2-int(i*lg2+1e-7);
a[i]=pow(10.0,x);
}
//for(int i=0;i<20;i++) cout<<"2^"<<i<<" :"<<a[i]<<endl;
} int main(){
ini();
int n;
while(scanf("%d",&n)!=EOF && n!=-1){
int cnt[10]={0};
for(int i=0;i<=n;i++){
cnt[a[i]]++;
}
printf("%d",cnt[1]);
for(int i=2;i<=9;i++){
printf(" %d",cnt[i]);
}
printf("\n");
}
return 0;
}

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. 用c实现的各种排序的方法

    #include <stdio.h> void swap(int *a, int *b); void bubble_sort(int a[], int n); void select_so ...

  2. mIsFunui-判断Funui方法

    1.有时候我们根据自己的需要,修改了frameword下的代码,但是,我们又不希望影响第三方,这时候我们就可以在修改处添加一个我们自己的标志位,如,mIsFunui 它是定义在我们自定义的theme里 ...

  3. 前端面试题(计算机网络/http/https)

    (前端面试题大全,持续更新) 输入url的一系列过程 http缓存(缓存生效的情况),拓展下 get与post的异同,POST一般可以发送什么类型的文件 jsonp有什么不好的地方 http请求头(h ...

  4. css的三种表现形式

    1.行内样式(内嵌样式):结构的内部,即写在标签内的样式:写在标签的开始部分内部,style属性当中:<标记 style="样式的属性名1:样式的属性值1:属性名2:属性值2:.... ...

  5. C#调用第三方ocx控件 (winform /aspx)

    C#调用第三方ocx控件   1..net环境在工具箱上点右键,选择自定义工具箱,然后选择你需要的COM或者OCX控件就可以了. 2.在自定义工具箱中加入相应的控件,设置id,在客户端脚本中直接引用它 ...

  6. ClickOnce

    Clic WPF ClickOnce应用程序IIS部署发布攻略   WPF程序非常适合公司内网使用,唯一缺点就是客户端要安装.net框架4.0.优势也很明显,在客户端运行的是一个WinForm程序,自 ...

  7. html doctype作用

    简单介绍下html页面中DOCTYPE声明的作用: <!doctype html>告诉浏览器是使用标准模式还是怪异模式渲染页面. 1.为html页面添加了doctype,则浏览器在stan ...

  8. (转)DOS批处理的字符串功能

    批处理有着具有非常强大的字符串处理能力,其功能绝不低于C语言里面的字符串函数集.批处理中可实现的字符串处理功能有:截取字符串内容.替换字符串特定字段.合并字符串.扩充字符串等功能.下面对这些功能一一进 ...

  9. LA 3026 - Period KMP

    看题传送门:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  10. AE开发概念辨析

    樱木 原文 AE开发之概念辨析2,AE开发涉及相关概念,AE开发相关概念 1 AE中的类库 AE总共包括了21个子库,分别是SYSTEM,SYSTEMUI,GEOMETRY,DISPLAY,SERVE ...