|
发表于 2006-11-22 17:46:45
|
显示全部楼层
- #include<stdio.h>
- #define __USE_ISOC99
- #include<stdlib.h>
- #include<string.h>
- #define MAXNL 11
- long long tenpower[MAXNL]= {1,10, 0};// 10^i
- long long ftenpower[MAXNL]= { 0,1,0};// nnumone(10^i -1)
- long long stepnum[MAXNL]={0};
- int tens[MAXNL]={0};
- long long nnumone(int len)
- {
- int i;
- long long rt=0;
- for(i=len-1;i>=0;--i)
- {
- if(tens[i]>1) rt+=tenpower[i]+tens[i]*ftenpower[i];
- else if(tens[i]==1)
- rt+=ftenpower[i]+stepnum[i]+1;
- }
- return rt;
- }
- int settens(long long n)
- {
- int i, j;
- lldiv_t qr;
- i=0;
- qr.quot=n;
- while(qr.quot)
- {
- qr=lldiv(qr.quot, 10L);
- tens[i++]=qr.rem;
- }
- for(j=1;j<i;++j)
- {
- stepnum[j]=stepnum[j-1]+tens[j-1]*tenpower[j-1];
- }
- return i;
- }
- int main(int argc, char * argv[])
- {
- int i,len=0;
- long long rt, n=1, c;
- for(i=1;i<MAXNL;++i)
- {
- tenpower[i]=tenpower[i-1]*10;
- ftenpower[i]=tenpower[i-1]*i;
- }
-
- do
- {
- len=settens(n);
- rt=nnumone(len);
- c=n-rt;
- if(c>len)
- {
- n+=c/len+1;
- }
- else if(c<0)
- {
- n+=(-c);
- }
- else{
- if(c==0)
- printf("%lld\n",n);
- ++n;
- }
- }while(len<MAXNL);
- return 0;
- }
复制代码
this is the result
- time ./a.out
- 1
- 199981
- 199982
- 199983
- 199984
- 199985
- 199986
- 199987
- 199988
- 199989
- 199990
- 200000
- 200001
- 1599981
- 1599982
- 1599983
- 1599984
- 1599985
- 1599986
- 1599987
- 1599988
- 1599989
- 1599990
- 2600000
- 2600001
- 13199998
- 35000000
- 35000001
- 35199981
- 35199982
- 35199983
- 35199984
- 35199985
- 35199986
- 35199987
- 35199988
- 35199989
- 35199990
- 35200000
- 35200001
- 117463825
- 500000000
- 500000001
- 500199981
- 500199982
- 500199983
- 500199984
- 500199985
- 500199986
- 500199987
- 500199988
- 500199989
- 500199990
- 500200000
- 500200001
- 501599981
- 501599982
- 501599983
- 501599984
- 501599985
- 501599986
- 501599987
- 501599988
- 501599989
- 501599990
- 502600000
- 502600001
- 513199998
- 535000000
- 535000001
- 535199981
- 535199982
- 535199983
- 535199984
- 535199985
- 535199986
- 535199987
- 535199988
- 535199989
- 535199990
- 535200000
- 535200001
- 1111111110
- real 0m0.006s
- user 0m0.008s
- sys 0m0.000s
复制代码 |
|