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