Codeforces Round #306 (Div. 2) 550C - Divisibility by Eight Solution
Problem Link: https://codeforces.com/problemset/problem/550/C
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- string s;
- cin >> s;
- s = "00" + s;
- int n = s.size();
- int i, j, k, a, b, c;
- bool f = false;
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; j < n; j++) {
- for (int k = j + 1; k < n; k++) {
- a = s[i] - '0';
- b = s[j] - '0';
- c = s[k] - '0';
- int num1 = (a * 100) + (b * 10) + c;
- if (num1 % 8 == 0) {
- cout << "YES" << endl;
- cout << num1 << endl;
- return 0;
- }
- }
- }
- }
- cout << "NO" << endl;
- }
No comments