HDU 3215 The first place of 2^n (数论-水题)

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

2009 Shanghai Network Contest Host
by DHU

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;
}
时间: 2024-11-05 08:02:10

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

HDU 4006 The kth great number (基本算法-水题)

The kth great number Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too mu

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

HDU - 4788 Hard Disk Drive Time Limit:1000MS   Memory Limit:32768KB   64bit IO Format:%I64d & %I64u [Submit]  [Go Back]  [Status] Description Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gift because you will

HDU 5344(2015多校5)-MZL&#39;s xor(水题)

题目地址:HDU 5344 题意:求所有(Ai+Aj)的异或值. 思路:可以发现(Ai+Aj)和(Aj+Ai)的异或值为0,所以最后只剩下(Ai+Ai). #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm>

HDU 2674 N!Again (数论-水题)

N!Again Problem Description WhereIsHeroFrom:             Zty, what are you doing ? Zty:                                     I want to calculate N!...... WhereIsHeroFrom:             So easy! How big N is ? Zty:                                    1 <=

HDU 4143 A Simple Problem(数论-水题)

A Simple Problem Problem Description For a given positive integer n, please find the smallest positive integer x that we can find an integer y such that y^2 = n +x^2. Input The first line is an integer T, which is the the number of cases. Then T line

hdu 1465(不容易系列之一)(水题,错排公式)(a[n]=(n-1)*(a[n-1]+a[n-2]))

不容易系列之一 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14924    Accepted Submission(s): 6207 Problem Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好"一件"事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总

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

题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题解:统计数字个数和频率,排序后输出. Sample Input36100 100 100 99 98 1016100 100 100 99 99 1016100 100 98 99 99 97 Sample OutputCase #1:10000Case #2:Bad MushroomCase #3

HDU ACM 5214 Movie -&gt;贪心+自然溢出取模-&gt;水题里的学问

分析:贪心,首先找到最右边的第一个左边界和最左边的第一个右边界.之后在判断是否有一个及一个以上的区间在这两个值之间,若有则能找到符合题意的三个区间,否则不能. 注意:这里利用的unsigned int的自然溢出决解了取模问题:第二个是一定生成完数据后在交换Li和Ri的值,这里被坑残了. #include<iostream> using namespace std; //__int64 mod=4294967296;由于4294967296-1刚好是unsigned int类型的最大值,对它取模

hdu 1849 Rabbit and Grass 谁都喜欢刷水题。。尼姆博弈

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2507    Accepted Submission(s): 1888 Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去