题目链接:https://ac.nowcoder.com/acm/contest/70/B
题目大意:
略
分析:
先DFS求出所有幸运数,然后暴力即可
代码如下:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std; #define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef set< int > SI;
typedef vector< int > VI;
const double EPS = 1e-;
const int inf = 1e9 + ;
const LL mod = 1e9 + ;
const int maxN = 1e5 + ;
const LL ONE = ; LL l, r, ans;
LL lucky[], n; // 求所有幸运数
inline void dfs(LL x, int cnt) {
if(cnt > ) return;
lucky[n++] = x;
dfs(x* + , cnt + );
dfs(x* + , cnt + );
} int main(){
INIT();
cin >> l >> r;
lucky[n++] = ;
dfs(, );
sort(lucky, lucky + n); int j = lower_bound(lucky, lucky + n, l) - lucky; while(l <= r) {
ans += (min(lucky[j], r) - l + ) * lucky[j];
l = lucky[j++] + ;
} cout << ans << endl;
return ;
} /*
1 1000000000
1394672350065645019 1 1000
1397683 447 447477474
168389348342066109 1 436278568
163403864955643707 1 4328955
16190029435407 4328956 4444444
513284393116 4328956 436278568
163387674926208300 2354 543262
231508617956 999999999 1000000000
8888888888
*/