B.cpp 585 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. inline int f(int n) {
  4. int tot = 0;
  5. while (n % 7 == 0) {
  6. ++tot;
  7. n /= 7;
  8. }
  9. return tot;
  10. }
  11. inline int g(int n) {
  12. int tot = 0;
  13. while (n > 0) {
  14. if (n % 10 == 7)++tot;
  15. n /= 10;
  16. }
  17. return tot;
  18. }
  19. int main() {
  20. int T;
  21. cin >> T;
  22. while (T--) {
  23. int L, R;
  24. cin >> L >> R;
  25. int tot = 0;
  26. for (int n = L; n <= R; n++) {
  27. tot += f(n) + g(n);
  28. }
  29. cout << tot << endl;
  30. }
  31. return 0;
  32. }