您的位置:首页 > 其它

HUST 1600 Lucky Numbers

2016-03-07 08:28 316 查看
暴力打表。

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: