#include <bits/stdc++.h>
using namespace std;
vector<bool> visited(200005, false);
vector<long long> adj[200005];
vector<long long> tmp(200005);
vector<long long> parent(200005, -1);
long long ed, no;
long long expo(long long x, long long n, long long M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return (expo((x * x) % M, n / 2, M)) % M;
  else
    return (x * expo((x * x) % M, (n - 1) / 2, M)) % M;
}
bool sortbysec(
    pair<pair<long long, long long>, pair<long long, long long>> p1,
    pair<pair<long long, long long>, pair<long long, long long>> p2) {
  if (p1.first.first != p2.first.first)
    return p1.first.first > p2.first.first;
  else {
    return p1.second.first < p2.second.first;
  }
}
void dfs(long long v1, long long p) {
  long long cnt = 1;
  for (long long j = 0; j < adj[v1].size(); j++) {
    long long x = adj[v1][j];
    if (x == p) continue;
    while (tmp[v1] == cnt || tmp[p] == cnt) cnt++;
    tmp[x] = cnt;
    cnt++;
    dfs(x, v1);
  }
}
long long find(vector<long long> &parent, long long i) {
  while (parent[i] != i) {
    parent[i] = parent[parent[i]];
    i = parent[i];
  }
  return parent[i];
}
void Union(vector<long long> &parent, long long i, long long j) {
  long long x = find(parent, i);
  long long y = find(parent, j);
  parent[x] = y;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, k, a, b, c, t, x, y, n, m, z, flag = 0, ans = 0, sum = 0;
  t = 1;
  while (t--) {
    string st, p, s1, s2;
    long long d;
    cin >> n >> k;
    vector<long long> v(n);
    for (i = 0; i < n; i++) {
      cin >> v[i];
    }
    if (k == 1 || k == -1) {
      sum = 0;
      map<long long, long long> make_pair;
      for (j = 0; j < n; j++) {
        sum += v[j];
        if (sum == 1) {
          ans++;
        }
        if (make_pair.find(sum - 1) != make_pair.end())
          ans += make_pair[sum - 1];
        make_pair[sum]++;
      }
    }
    if (k == -1) {
      sum = 0;
      map<long long, long long> make_pair;
      for (j = 0; j < n; j++) {
        sum += v[j];
        if (sum == -1) {
          ans++;
        }
        if (make_pair.find(sum + 1) != make_pair.end())
          ans += make_pair[sum + 1];
        make_pair[sum]++;
      }
    }
    if (k == 1 || k == -1) {
      cout << ans;
      return 0;
    }
    ans = 0;
    for (i = 0; i <= 50; i++) {
      x = pow(k, i);
      if (x >= LONG_LONG_MAX) break;
      sum = 0;
      map<long long, long long> make_pair;
      for (j = 0; j < n; j++) {
        sum += v[j];
        if (sum == x) {
          ans++;
        }
        if (make_pair.find(sum - x) != make_pair.end())
          ans += make_pair[sum - x];
        make_pair[sum]++;
      }
    }
    cout << ans;
  }
  return 0;
}
