はまやんはまやんはまやん

hamayanhamayan's blog

Average [yukicoder No.682]

https://yukicoder.me/problems/no/682

解法

https://yukicoder.me/submissions/256920

iが全探索できるので、iを全探索して総和が3で割り切れるなら答えとしてカウントしていこう。

int A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B;

    int ans = 0;
    rep(i, A, B + 1) {
        int sm = A + B + i;
        if (sm % 3 == 0) ans++;
    }
    cout << ans << endl;
}