0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-21 04:25:24 +00:00
OI-codes/S2OJ/1808/1808.cpp

60 lines
11 KiB
C++
Raw Normal View History

#include <iostream>
#include <bitset>
using std::cin;
using std::cout;
const char endl = '\n';
const int SIZE = 1000000;
const int f[]{1, 376414, 832548, 1288829, 1744957, 2196801, 2647717, 3090921, 3526441, 3951373, 4366881, 4823016, 5304767, 5797145, 6290673, 6782005, 7272531, 7758911, 8238397, 8710537, 9182259, 9638540, 10130919, 10610576, 11103530, 11590746, 12080514, 12565095, 13045217, 13523104, 13996048, 14452176, 14945704, 15438659, 15913606, 16403908, 16892728, 17371944, 17858308, 18339126, 18810720, 19262564, 19753896, 20241112, 20731415, 21199400, 21684698, 22170474, 22655526, 23128983, 23601311, 24052227, 24542753, 25032521, 25521341, 26006640, 26480513, 26967739, 27450345, 27929455, 28401297, 28844501, 29330881, 29815462, 30294678, 30780454, 31267681, 31727884, 32207446, 32681532, 33151142, 33586662, 34066148, 34546270, 35032634, 35517686, 36000292, 36479855, 36928876, 37398606, 37865238, 38290170, 38762310, 39240197, 39721015, 40194472, 40673582, 41147668, 41617399, 42050820, 42514128, 42929636, 43401358, 43874302, 44345896, 44818224, 45290066, 45759676, 46226308, 46689617, 47111408, 47567543, 48049294, 48541672, 49035200, 49526532, 50017058, 50503438, 50982924, 51455064, 51926787, 52408538, 52900917, 53398018, 53897102, 54395977, 54894265, 55390377, 55882155, 56370125, 56858337, 57350716, 57847817, 58346902, 58846683, 59346651, 59846495, 60345547, 60842737, 61337763, 61832644, 62326172, 62825257, 63325038, 63822619, 64321882, 64821478, 65319368, 65818160, 66315615, 66811193, 67302525, 67801400, 68301369, 68800632, 69295187, 69792676, 70292150, 70790950, 71286704, 71781714, 72272240, 72770528, 73270372, 73769969, 74267458, 74763403, 75261352, 75759528, 76256606, 76751556, 77237936, 77734048, 78233100, 78730990, 79230465, 79728414, 80220835, 80714564, 81209374, 81704150, 82183636, 82675414, 83172604, 83671396, 84170196, 84668373, 85162102, 85646751, 86134012, 86626602, 87098742, 87586712, 88081738, 88579193, 89074947, 89572025, 90066836, 90554097, 91029272, 91513943, 91985665, 92473877, 92968758, 93464336, 93959346, 94454296, 94949072, 95441663, 95926334, 96400456, 96856737, 97349116, 97828773, 98321727, 98808943, 99298711, 99783292, 100263414, 100741301, 101214245, 101706624, 102203725, 102702810, 103202591, 103702559, 104202403, 104701455, 105198645, 105693671, 106188553, 106668210, 107167294, 107654510, 108153409, 108643572, 109140448, 109631937, 110124935, 110615087, 111104171, 111597126, 112096907, 112595805, 113093028, 113592811, 114091416, 114589182, 115087419, 115585177, 116080739, 116567955, 117067924, 117558087, 118057869, 118549358, 119048443, 119540444, 120037758, 120529914, 121025142, 121514910, 122014754, 122511631, 123010236, 123509320, 124005152, 124504321, 124999108, 125496724, 125991519, 126476100, 126975152, 127466641, 127964408, 128456409, 128955577, 129444362, 129941989, 130432182, 130927550, 131407672, 131904862, 132397860, 132896097, 133393412, 133888199, 134385825, 134870791, 135365762, 135853349, 136331236, 136826262, 137316414, 137814172, 138306328, 138803945, 139294138, 139789108, 140268614, 140761870, 141234814, 141729695, 142218779, 142714341, 143209569, 143704364, 144199733, 144687320, 145180576, 145654893, 146111021, 146604549, 147097504, 147572451, 148062753, 148551573, 149030789, 149517153, 149997971, 150469565, 150963093, 151462178, 151961959, 152459540, 152958803, 153458399, 153956289, 154455081, 154952536, 155448114, 155941069, 156440850, 156939748, 157436971, 157936754, 158435359, 158933125, 159431362, 159929120, 160424683, 160899630, 161397210, 161894433, 162373649, 162870480, 163366197, 163847036, 164342308, 164834857, 165316243, 165806546, 166305809, 166805591, 167302422, 167797534, 168296440, 168794207, 169291182, 169787228, 170282584, 170771404, 171271001, 171769606, 172265322, 172764228, 173259686, 173756940, 174255103, 174749456, 175244788, 175724004, 176221894, 176719661, 177200500, 177698266, 178195520, 178676906, 179174054, 179669963, 180151504, 180637868, 181136660, 181634897, 182130170, 182627145, 183125307, 183622455, 184112943, 184610047, 185104839, 185585657, 186083112, 186580870, 187073419, 187569466, 188063819, 188559727, 189056831, 189540681, 190034892, 190506486, 1910020
bool check(int x) {
int s = 0;
std::bitset<128> f;
f.set(0);
while (x) {
int k = x % 10;
f |= f << k;
s += k;
x /= 10;
}
return s % 2 == 0 && f[s >> 1];
}
int solve(int x) {
int res = f[x / SIZE];
for (int i = x / SIZE * SIZE + 1; i <= x; i++) {
if (check(i)) res++;
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
// for (int i = 0, cnt = 0; i <= 1e9; i++) {
// if (check(i)) cnt++;
// if (i % SIZE == 0) {
// cout << cnt << ", ";
// std::cerr << i << endl;
// }
// }
int l, r;
cin >> l >> r;
cout << solve(r) - solve(l - 1) << endl;
return 0;
}