abc176_b - Multiple Of 9

Check if the sum of digits is multiple of $9$.

Time complexity: $O(n)$

Memory complexity: $O(n)$

Click to show code.


using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(void)
{
    ios::sync_with_stdio(false), cin.tie(NULL);
    string n;
    cin >> n;
    ll sum =
        accumulate(begin(n), end(n), 0LL, [](ll acc, char c) { return acc + (c - '0'); });
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
    return 0;
}