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. 6 Spring Boot 静态资源处理

    转自:https://blog.csdn.net/catoop/article/details/50501706

  2. 2016最热门的PHP框架(一共五款)

    摘要: 兄弟连IT教育作为全国最大的PHP培训机构,迄今已有10年的教育历史.6大特色课程:PHP编程.安卓培训.JAVAEE+大数据.UI设计.HTML5培训.云计算架构师,在目前IT市场特别火,每 ...

  3. Loading half a billion rows into MySQL---转载

    Background We have a legacy system in our production environment that keeps track of when a user tak ...

  4. call.apply.冒充对象继承

    call方法:让调用对象执行,然后第一参数是谁.调用对象的this就改变,指向谁,后边跟参数,依次对应传入 apply方法:让调用对象执行,然后第一参数是谁.调用对象的this就改变指向是谁,后边跟参 ...

  5. 每日技术总结:Yarn和Npm大PK

    今天想用npm安装vue-cli@2.9 npm install --global vue-cli@2.9 卡半天,安装不成功,清空缓存,换taobao源重来,还是一样. 无奈之下换yarn yarn ...

  6. POJ 1064 Cable master 浮点数二分

    http://poj.org/problem?id=1064 题目大意: 有N条绳子,他们的长度分别为Li,如果从它们中切割出k条长度相同的绳子的话,这K条绳子每条能有多长? 思路: 二分,设答案为m ...

  7. Exsi SSH 服务配置

    vi /etc/ssh/sshd_conf禁止口令验证PasswordAuthentication no禁止root登录PermitRootLogin no ESXi Shell F2--F2--Tr ...

  8. 7 Java Performance Metrics to Watch After a Major Release--转

    原文地址:https://dzone.com/articles/7-java-performance-metrics-to-watch-after-a-major-1 The Java perform ...

  9. Swift3.0 功能二 (表情键盘与图文混排)

    随着iOS越来越多表情键盘以及图文混排的需求,本文运用Swift3.0系统的实现其功能以及封装调用方法,写的不好,如有错误望各位提出宝贵意见,多谢 项目源码地址: 相关知识点都有标识 项目源码地址 废 ...

  10. php 下载图片到服务器

    function saveImage($path) { if(!preg_match('/\/([^\/]+\.[a-z]{3,4})$/i',$path,$matches)) die('Use im ...