15-Lucky Array 4, 7

Source: Internet
Author: User

/* Topic content:

YF does not love fame and fortune, so he neither likes 6, nor does he like 8. His lucky numbers are 4 and 7. If a number contains only 4 and 7, he thinks the number is his lucky number.
Now you have two positive integers, a, a, a, a, a number of lucky numbers between A and B, including a, b itself.

Enter a description

The first line enters the number n, which indicates that there are n groups of AB
Line 2nd starts with a set of a B and a space separated by each line.


Output description

Each line outputs a number, that is, the number of lucky numbers between A and B.


Input sample

3
11 20
4 7
1 10
Output sample

0
2
2
*/

#include <iostream>
using namespace Std;
int lucky[10000005]; Attention to size, small has always been the answer wrong

void Countlucky () {
for (int i = 1; I <= 10000000; i++) {
int C, D, E, F, G, h, y = i;
int flag = 1;
if (y% 10 = = 0)
Flag = 0;
while (y% && flag) {
c = y% 10; Y/= 10;
if (c! = 4 && c! = 7)
Flag = 0;
}
if (flag && y = = 0)//101 y = 10
Lucky[i] = 1;
c = y% 10; Y/= 10;
d = y% 10; Y/= 10;
E = y% 10; Y/= 10;
f = y% 10; Y/= 10;
g = y% 10; Y/= 10;
h = y% 10; Y/= 10;
if (I < 10)
LUCKY[4] = lucky[7] = 1;
if (I < 100) {
if ((c = = 4 | | c = 7) && (d = = 4 | | d = = 7))
Lucky[i] = 1;
//        }
if (I < + && (c = = 4 | | c = 7) && (d = = 4 | | d = = 7) && (E = = 4 | | e = = 7))
Lucky[i] = 1;
if (I < 10000 && (c = = 4 | | c = = 7) && (d = = 4 | | d = = 7) && (E = = 4 | | e = = 7) && Amp (f = = 4 | | f = = 7))
Lucky[i] = 1;
if (I < 100000 && (c = = 4 | | c = = 7) && (d = = 4 | | d = = 7) && (E = = 4 | | e = = 7) & & (F = = 4 | | f = 7)
&& (g = = 4 | | g = = 7))
Lucky[i] = 1;
if (I < 100000 && (c = = 4 | | c = = 7) && (d = = 4 | | d = = 7) && (E = = 4 | | e = = 7) & & (F = = 4 | | f = 7)
&& (g = = 4 | | g = 7) && (h = = 4 | | h = = 7))
Lucky[i] = 1;
Lucky[i] + = lucky[i-1];
}
}

int main () {
Ios::sync_with_stdio (FALSE);
int n;
CIN >> N;
Countlucky ();
while (n--) {
int A, B;
Cin >> a >> b;
cout << Lucky[b]-lucky[a-1] << Endl;
//    }
return 0;
}

15-Lucky Array 4, 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.