描述
求整数序列中位置L到位置R中一共有多少个7。对于每个数7的个数的定义为,十进制各个位置上一共有多少个7,以及能够被7整除的次数。
输入
第一行是一个整数T,代表测试数据的组数。每组数据中两个整数L,R。其中。
输出
共T行,共有多少个7。
样例输入
2
1 10
47 50
样例输出
2
3
提示
第一组样例中1到10中,只有7被计数,它十进制下有7并且是7的倍数,所以被计数2次。第二组样例中47有1个7,49可以被7整除2次,所以共被计数3次。
#include <iostream>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int count = 0;
int L, R;
cin >> L >> R;
for(int j = L; j <= R; j++)
{
int temp1 = j, temp2 = j;
while(temp1 % 10 == 7)
{
count++;
temp1 /= 10;
}
while(temp2 % 7 == 0)
{
count++;
temp2 /= 7;
}
}
cout << count << endl;
}
return 0;
}