Nyoj 1172 Unlucky number

Source: Internet
Author: User

Unlucky number time limit: +Ms | Memory Limit:65535KB Difficulty:0
Describe
We define that only the number of combinations of 1 and 7 in the interval "l,r" are unlucky numbers, for example: 1, 7, 11, 17 are unlucky numbers, and 13, 27 is not, ask in the interval "l,r" How many unlucky numbers??
Input
There are multiple sets of test data (no more than 100 groups)
Enter two integers per group l,r (0 =< l<= R <= 10^18)
Output
Enter one result per line
Sample input
1 7
Sample output
2
Uploaded by

Acm_ Zhang Shujun

Idea: The same as the ugly number of ideas with the preceding number to facilitate the number of the following

Make a watch.

Then judge the position of the l,r in the table, statistics unlucky numbers on the line

#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm>using 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<c; i++)        {            if (a[i]<=l) l=i;            if (a[i]>r)            {                r=i;                break;            }        }        if (a[l]==l| | l==0) l--;        printf ("%d\n", R-l-1);}    }        



Nyoj 1172 Unlucky number

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.