1 #include <iostream>
2
3 using namespace std;
4 long long p;
5 long long a[20];
6 long long solve(long long n){
7 long long left,m,sum =0;
8 for(int i=1;i<12;i++){
9 left = n/a[i]-1;
10 sum += left*a[i-1];
11 m = (n%a[i]-n%a[i-1])/a[i-1];
12 if(m>0) sum += a[i-1];
13 else if(m==0) sum += n%a[i-1]+1;
14 if(n<a[i]) break;
15 }
16 return sum;
17 }
18
19 int main()
20 {
21 a[0] =1;
22 for(int i=1;i<15;i++)
23 a[i] =a[i-1]*10;
24 long long m,n;
25 while(cin>>m>>n){
26 if(m<0)
27 break;
28 if(n==0){
29 cout<<1<<endl;
30 continue;
31 }
32 long long res1 = solve(n);
33 long long res2 = solve(m-1);
34 //cout<<p<<endl;
35 //cout<<res1<<" "<<res2<<endl;
36 cout<<res1-res2<<endl;
37 }
38 return 0;
39 }
40 /**
41 if(n<0)
42 return 0;
43 long long low;
44 long long high;
45 long long cur;
46 p =1;
47 int tmp=0;
48 long long cnt =0;
49 while(n/p!=0){
50 tmp ++;
51 low = n-(n/p)*p;
52 high = n/(p*10)-1;
53 cur = (n/p)%10;
54 switch (cur){
55 case 0:
56 cnt += high*p+low+1;
57 break;
58 default:
59 cnt += (high+1)*p;
60 break;
61 }
62 p =p*10;
63 }
64 //for(int i=0;i<tmp;i++){
65 // cnt -= a[i];
66 //}
67 return cnt;
68 */
poj 3286 统计0的个数
时间: 2024-10-21 16:59:55