题解 | #幸运数字Ⅱ#

幸运数字Ⅱ

https://ac.nowcoder.com/acm/problem/15291

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 10010;
LL l, r, sum, cnt;
LL a[N];

void fun(LL x)
{
    if(x > 4444444444)return;
    a[++cnt] = x * 10 + 4;
    a[++cnt] = x * 10 + 7;
    fun(x * 10 + 4);
    fun(x * 10 + 7);
}
int main()
{
    cin>>l>>r;
    fun(0);
    sort(a + 1, a + 1 + cnt);
    LL x = lower_bound(a + 1, a + 1 + cnt, l) - a;
    LL y = lower_bound(a + 1, a + 1 + cnt, r) - a;
    
    if(x == y)
    {
        cout<<(r - l + 1) * a[x]<<endl;
        return 0;
    }
    for(LL i = x; i <= y; i ++)
    {
        if(i == x)sum += (a[x] - l + 1) * a[i];
        else if(i == y)sum += (r - a[i - 1]) * a[i];
        else sum += (a[i] - a[i - 1]) * a[i];
    }
    cout<<sum<<endl;
    return 0;
}
竞赛奋斗日志 文章被收录于专栏

一个奋斗的蒟蒻

全部评论

相关推荐

想玩飞盘的菠萝蜜在春...:上交✌🏻也拒?
点赞 评论 收藏
分享
迷茫的大四🐶:看来已经准备换人了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务