HDU 3215 The first place of 2^n(计算2^0到2^n首位出现的1,2,3...9的个数)
来源:互联网 发布:淘宝自动好评加分吗 编辑:程序博客网 时间:2024/06/05 17:35
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.
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.
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
01310-1
Sample Output
1 0 0 0 0 0 0 0 01 1 0 0 0 0 0 0 01 1 0 1 0 0 0 1 04 2 1 1 1 1 0 1 0
Source
2009 Shanghai Network Contest Host by DHU
Recommend
zhuweicong | We have carefully selected several similar problems for you: 3219 3217 3212 3218 3216
题目大意:
计算2^0到2^n首位出现的1,2,3...9的个数。
解题思路:利用log10计算整理一下,根据小数部分=浮点数-整数。
#include<iostream>#include<cstdio>#include<cmath>using namespace std;const int maxN=11000;const double lg2=log10(2);int a[maxN],n;void initial(){ 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]=(int)(pow(10.0,x)+1e-7); } //for(int i=0;i<20;i++) cout<<"2^"<<i<<" :"<<a[i]<<endl;}int main(){ initial(); 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<10;i++){ printf(" %d",cnt[i]); } printf("\n"); } return 0;}
0 0
- HDU 3215 The first place of 2^n(计算2^0到2^n首位出现的1,2,3...9的个数)
- HDU/HDOJ 3215 The first place of 2^n
- Hdu 3215 The first place of 2^n (对数)
- HDU 3215 The first place of 2^n (数论-水题)
- HDU 3215 The first place of 2^n(数论-其他)
- 写一个函数,计算0到n之间2的个数 (1-9的个数)
- hdoj The first place of 2^n 3215 (数学技巧&预处理)
- 一道让我纠结的水题——上海邀请赛The first place of 2^n
- Hard 计算0到n之间2的个数 @CareerCup
- 2的N次方首位数
- 统计数字 1,2,3 ... n 出现 0~9 的个数
- 计算0到n中数字2出现的次数
- 计算1 到 N 之间 某个数字出现的个数
- 1!+2!+...+30! 计算从1到n个数的阶乘的总和
- 计算从1到n(包括n)之间出现的各位数字的个数
- 写一个函数,计算0到n之间2的个数。
- 给定一个正整数N,从1到N所有整数,计算出现1的个数
- 给定一个正整数N计算从1到N中1出现的个数
- Mac 远程连接 Windows
- Mysql 存储过程示例
- HDU - 2604 Queuing DFA + 矩阵二分
- 使用Cocos 坑 总结
- 面向对象(四)内部类与异常机制
- HDU 3215 The first place of 2^n(计算2^0到2^n首位出现的1,2,3...9的个数)
- android 电池(二):android关机充电流程、充电画面显示
- vs2005 C++连接SQL2008数据库进行插入 删除 登陆查询
- HTML网页Javascript跳转代码
- 【JavaScript】Ext JS - 高效的编码风格指南
- Monkey测试3——Monkey测试结果分析
- DB2常用函数详解(二):类型转换函数
- MySQL Order By索引优化
- 黑马程序员——交通灯管理系统的学习与分析