#include <bits/stdc++.h>
using namespace std;
int n, k, ai;
long long SUM, ans;
set<long long> PW;
map<long long, int> SUMS;
int main() {
  scanf("%d%d", &n, &k);
  SUMS[0] = 1;
  PW.insert(1);
  if (k == -1) PW.insert(-1);
  if (abs(k) > 1)
    for (long long p = k; p < 1e16; p *= k) PW.insert(p);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ai);
    SUM += ai;
    for (auto p : PW) {
      auto f = SUMS.find(SUM - p);
      if (f != SUMS.end()) ans += f->second;
    }
    SUMS[SUM]++;
  }
  cout << ans << endl;
}
