Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- string s;
- cin >> s;
- if(n <= 20) {
- int comb = 0;
- for(int mask = 0; mask < (1 << n); mask++) {
- string tmp = "";
- for(int i = 0; i < n; i++) {
- if(mask & (1 << i)) {
- tmp += s[i];
- }
- }
- int number = 0;
- if(tmp.size() >= 3) {
- number = (100 * (tmp[tmp.size() - 3] - '0')) + (10 * (tmp[tmp.size() - 2] - '0') + tmp[tmp.size() - 1]);
- }
- else if(tmp.size() >= 2) {
- number = (10 * (tmp[tmp.size() - 2] - '0')) + (tmp[tmp.size() - 1] - '0');
- }
- else if(tmp.size() >= 1){
- number = (tmp[tmp.size() - 1] - '0');
- }
- if(number % 8 == 0) {
- comb++;
- }
- }
- int mod = 1e9 + 7;
- cout << (comb % mod) - 1 << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement