HUST 1600 Lucky Numbers

暴力打表。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;

long long a[10000];
long long L, R;
int tot;

void dfs(long long num, int len)
{
    if (len > 16) return;
    if (num>=1&&num<=1000000000000000&&num % 48 == 0) a[tot++] = num;
    dfs(num * 10 + 4, len + 1);
    dfs(num * 10 + 8, len + 1);
}

void init()
{
    tot = 0;
    dfs(4, 1);
    dfs(8, 1);
}

int main()
{
    init();
    while (~scanf("%lld%lld", &L, &R))
    {
        long long ans = 0;
        for (int i = 0; i < tot; i++)
            if (a[i] >= L&&a[i] <= R) ans++;
        printf("%lld\n", ans);
    }
    return 0;
}

 

posted @ 2016-03-07 08:28  Fighting_Heart  阅读(137)  评论(0编辑  收藏  举报