#include <bits/stdc++.h>
using namespace std;
long long cum[(int)1e6], input[(int)1e6], k, ans;
char c;
int sz, t;
map<long long, vector<int>> pos;
int main() {
  cin >> sz >> k;
  for (int i = 0; i < sz; i++) {
    scanf("%c%d", &c, &t);
    input[i] = t;
    if (i == 0) {
      cum[0] = t;
    } else {
      cum[i] = cum[i - 1] + input[i];
    }
    pos[cum[i]].push_back(i);
  }
  for (long long target = 1; abs(target) <= 1e16; target *= k) {
    for (int i = 0; i < sz; i++) {
      if (i == 0) {
        ans += pos[target].size();
      } else {
        ans += pos[target + cum[i - 1]].end() -
               lower_bound(pos[target + cum[i - 1]].begin(),
                           pos[target + cum[i - 1]].end(), i);
      }
    }
    if ((k == 1) || (k == -1 && target == k)) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
