A

来源:互联网 发布:python griddata 编辑:程序博客网 时间:2024/06/05 18:04

点击打开链接


There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Now you are given two integers A and B, you have to find the number of integers from Ath number to Bth (inclusive) number, which are divisible by 3.

For example, let A = 3. B = 5. So, the numbers in the sequence are, 123, 1234, 12345. And 123, 12345 are divisible by 3. So, the result is 2.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case contains two integers A and B (1 ≤ A ≤ B < 231) in a line.

Output

For each case, print the case number and the total numbers in the sequence between Ath and Bth which are divisible by 3.

Sample Input

2

3 5

10 110

Sample Output

Case 1: 2

Case 2: 67


题解:一个数各位数字之和能被3整除,则此数能被3整除。

           例:12,123,12345,123456,12345678,123456789.

                  即位数为2,3,5,6,8,9.......的可以.

#include<cstdio>int main(){int t,j=1;scanf("%d",&t);while(t--){long long a,b,c=0,d=0;scanf("%lld %lld",&a,&b);    c=a/3*2;    if(a%3==0)      c=c-1;d=b/3*2;if(b%3==2)  d=d+1;printf("Case %d: %lld\n",j++,d-c);}}



原创粉丝点击