#include #define MAX_R 999 // solve() 関数で使用する csum_count を、コンパイル時に計算する関数 static inline constexpr std::array prepare() noexcept { std::array csum_count = { 0, }; // 変更回数の累積和( = 第 0 回目から第 i 回目までの間に何回使用言語を変更したか) csum_count[296] = 1, csum_count[417] = 1; // imos 法の発想で、局所的な言語変更の回数を指定 for (uint_fast32_t i = 0; i != MAX_R; ++i) csum_count[i + 1] += csum_count[i]; // imos 法の復元 return csum_count; } // 答えを計算する関数 static inline constexpr uint_fast32_t solve(const uint_fast32_t L, const uint_fast32_t R) noexcept { constexpr std::array csum_count = prepare(); // 大昔から各時点までに使用言語を変更した回数 ( = 累積和) return csum_count[R] - csum_count[L]; // 累積和さえあれば、区間和が答え } // プログラムの制御を行う関数 int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); uint_fast32_t L, R; std::cin >> L >> R; std::cout << solve(L, R) << '\n'; return 0; }