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); }}