标签:des style blog http color os io for
0 1 3 10 -1
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
题目大意“:
解题思路:妈呀,这是我们大东华09年出的题啊,好厉害,其实是好水啊。
题目大意就是计算2^1到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 (数论-水题),布布扣,bubuko.com
HDU 3215 The first place of 2^n (数论-水题)
标签:des style blog http color os io for
原文地址:http://blog.csdn.net/a1061747415/article/details/38335277