C++ 755

时间限制: 1.000 Sec  内存限制: 128 M

题目描述

You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?

Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.
Constraints
1≤N<109
N is an integer.

输入

Input is given from Standard Input in the following format:

N

输出

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

样例输入 Copy
575
样例输出 Copy
4
提示

There are four Shichi-Go-San numbers not greater than 575: 357,375,537 and 573.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N;
int ans = 0;

void dfs(ll n, bool use3, bool use5, bool use7)
{
    if (n > N) return;
    if (use3 && use5 && use7) ans++;
    dfs(n * 10 + 3, 1, use5, use7);
    dfs(n * 10 + 5, use3, 1, use7);
    dfs(n * 10 + 7, use3, use5, 1);
}

int main()
{
    cin >> N;
    dfs(0, 0, 0, 0);
    cout << ans << '\n';
    return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值