链接:http://acm.hdu.edu.cn/showproblem.php?pid=3215
利用对数求 N 的最高位 s=pow(10, log10(N)-[log10(N)]) ;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <math.h> 3 const double eps=1.0e-6; 4 int dp[10010][10]; 5 void Init( ) 6 { 7 int y; 8 double s=log10(2), t, x; 9 dp[0][1]=1; 10 for( int i=1; i<=10000; ++ i ){ 11 for( int j=1; j<10; ++ j ){ 12 dp[i][j]=dp[i-1][j]; 13 } 14 t=s*i; 15 x=t-(int)t; 16 y=( int )(pow( 10, x )+eps);// 注意有精度损失 17 dp[i][y]++; 18 } 19 } 20 int main( ) 21 { 22 Init( ); 23 int N; 24 while( ~scanf( "%d", &N ) ){ 25 if( N==-1 )break; 26 for( int i=1; i<10; ++i ){ 27 printf( i==9?"%d\n":"%d ", dp[N][i] ); 28 } 29 } 30 return 0; 31 }