The first place of 2^n
Problem Descriptionlmy 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, every consecutive 3 or 4 results, there must be one among them whose first digit are 1, and comes to The conclusion that first digit of 2n ' t evenly distributed between 1 and 9, and the number of 1s exceeds those of Others. YY now intends to the use of statistics to prove Lmy ' s discovery.
Inputinput 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.
Outputfor 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
Source2009 Shanghai Network Contest Host by Dhu
Recommendzhuweicong | We have carefully selected several similar problems for you:3219 3217 3212 3218 3216
To the effect of the topic ":
Mom, this is our big Donghua 09 out of the question Ah, good, is actually good water ah.
The main problem is to calculate 2^0 to 2^n this n number of the first 1 times, 2 times, ... 9 of the Times.
Problem Solving Ideas:
I'm not going to tell you that LOG10 will find what you're looking for.
Problem Solving Code:
#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 (number theory-water problem)