eolymp
bolt
Try our new interface for solving problems
Problems

Is it divisible by 2, 4 and 8?

published at 1/18/24, 12:00:19 am

include <iostream>

include <string>

using namespace std;

int main() { string n;

cin >> n;

int t = n.length(), a, b, c;

if (t == 1) {
    a = n[t - 1];
    b = a;
    c = a;
}
else if (t == 2) {
    a = n[t - 1];
    b = a + (n[t - 2] * 10);
    c = b;
}
else {
    a = n[t - 1];
    b = a + (n[t - 2] * 10);
    c = b + (n[t - 3] * 100);
}

cout << (a % 2 == 0 ? "Yes\n" : "No\n");
cout << (b % 4 == 0 ? "Yes\n" : "No\n");
cout << (c % 8 == 0 ? "Yes\n" : "No\n");

return 0; }