poao899 -8K 750MS G++ 0.42K 2009-10-22 21:18:22 .
唔只要TIOJ 1021 G.Counting Page Numbers過了這題就可以寫了ˊˇˋ
//*********************************************
#include<stdio.h>
unsigned __int64 count(int n){
unsigned __int64 cnt=0;
if(n==-1)return -1;
for(unsigned __int64 i=1;i*10<=n;i*=10){
int m=n/i/10;
cnt+=(m-1)*(i);
if((n/i)%10)
cnt+=i;
else
cnt+=n%i+1;
}
return cnt;
}
main(){
int a,b;
while(~scanf("%d%d",&a,&b)){
if(a>b){int c=a;a=b;b=c;}
//printf("%I64d %I64d\n",count(b),count(a));
printf("%I64u\n",count(b)-count(a-1));
}
}
沒有留言:
張貼留言