Nyoj 1172 unlucky number

Source: Internet
Author: User

Nyoj 1172 unlucky number
Unlucky number time limit: 1000 MS | memory limit: 65535 KB difficulty: 0

Description
We define that only the numbers of 1 and 7 in the range [l, r] are unlucky number. For example, the numbers 1, 7, 11, and 17 are unlucky numbers, 13 and 27 are not. How many unluky numbers are there in the range [l, r ??
Input
There are multiple groups of test data (no more than 100 groups)
Enter two integers (l, r (0 = <l <= r <= 10 ^ 18) in each group)
Output
Input a result per line
Sample Input
1 7
Sample output
2
Uploaded

ACM _ Zhang Shujun

Idea: Use the preceding number as the ugly number to facilitate the subsequent number.

Create a table

Then, determine the position of l and r in the table and count unlucky numbers.

#include
      
       #include
       
        #include
        
         #includeusing namespace std;long long a[1000000];int c;void init(){    c=0;    a[c++]=1;    a[c++]=7;    int k=0;    while(a[c-1]<1e18)    {        a[c++]=a[k]*10+1;        a[c++]=a[k]*10+7;        k++;    }}int main(){    init();    long long l,r;    while(cin>>l>>r)    {        int L=0,R=0;        for(int i=0; i
         
          r)            {                R=i;                break;            }        }        if(a[L]==l||l==0) L--;        printf("%d\n",R-L-1);    }}        
         
        
       
      



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.