#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
const long long MAX = 1e15 + 7;
int n, k;
int a[MAXN];
long long s[MAXN];
map<long long, int> mp;
void init();
void input();
void work();
long long check(long long tst);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
}
void work() {
  s[0] = 0;
  for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i];
  long long ans = 0;
  if (k == 1)
    ans = check(1);
  else if (k == -1)
    ans = check(1) + check(-1);
  else {
    long long nv = 1;
    while ((((nv) >= 0) ? (nv) : (-(nv))) < MAX) {
      ans += check(nv);
      nv *= k;
    }
  }
  printf("%I64d\n", ans);
}
long long check(long long tst) {
  long long ans = 0;
  mp.clear();
  for (int i = n - 1; i >= 0; --i) {
    ++mp[s[i + 1]];
    ans += mp[s[i] + tst];
  }
  return ans;
}
