Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const long long MOD = 1e9 + 7;
- int to_int(string & s) {
- int res = 0;
- for(int i = 0; i < (int) s.size(); i++) {
- res = (res * 10) + (s[i] - '0');
- }
- return res;
- }
- bool check(string & s) {
- if((int) s.length() < 3) {
- return (to_int(s) % 8 == 0);
- }
- else {
- int x = (int) s.length();
- int tmp = (s[x - 3] - '0') * 100 + (s[x - 2] - '0') * 10 + (s[x - 1] - '0');
- return (tmp % 8 == 0);
- }
- }
- int main() {
- int n;
- cin >> n;
- string s;
- cin >> s;
- long long res =0 ;
- if(n <= 25) {
- for(int bitmask = 0; bitmask < (1 << n); bitmask++) {
- string tmp = "";
- for(int i = 0; i < n; i++) {
- if(bitmask & (1 << i)) {
- tmp += s[i];
- }
- }
- if((int) tmp.length() > 0 and check(tmp)) {
- res++;
- res %= MOD;
- }
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment