求和
分段求和,处理边界
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
ll l, r;
ll ans = 0;
ll nums[10000], cnt;
void dfs(ll x)
{
if(x > (ll)5e9) return;
if(x >= l) nums[cnt++] = x;
dfs(x * 10 + 4);
dfs(x * 10 + 7);
}
int main()
{
cin >> l >> r;
dfs(0);
sort(nums, nums+cnt);
int x1 = lower_bound(nums, nums+cnt, l) - nums;
int x2 = lower_bound(nums, nums+cnt, r) - nums;
// 分段求和
ans += (nums[x1] - l + 1) * nums[x1];
for(int i = x1 + 1; i <= x2; ++i)
ans += (nums[i] - nums[i-1]) * nums[i];
ans -= (nums[x2] - r) * nums[x2];
cout << ans << endl;
return 0;
}
// 1000000000 1000000000
// 100000000 100000000