#include <bits/stdc++.h>
using namespace std;
double esp = 1e-8;
const long double PI = acos((long double)-1);
const long long int INF = 0x3f3f3f3fll;
const int MOD = 1e9 + 7ll;
const int maxn = 110100;
set<long long int> q;
vector<long long int> tq;
long long int A[maxn];
map<long long int, int> qu;
int main() {
  long long int n, k;
  q.clear();
  scanf("%I64d%I64d", &n, &k);
  qu.clear();
  long long int sum = 0;
  for (int x = 1; x <= n; x++) {
    scanf("%I64d", &A[x]);
    sum += A[x];
    qu[sum]++;
  }
  q.insert(1);
  if (abs(k) == 1) {
    q.insert(k);
    q.insert(k * k);
  } else {
    long long int tem = 1;
    while (abs(tem) <= 1e16) {
      q.insert(tem);
      tem *= k;
    }
  }
  tq.clear();
  for (long long int v : q) tq.push_back(v);
  long long int ans = 0, tsum = 0;
  for (int x = 1; x <= n; x++) {
    for (long long int v : tq)
      if (qu.find(tsum + v) != qu.end()) ans += qu[tsum + v];
    tsum += A[x];
    qu[tsum]--;
  }
  printf("%I64d\n", ans);
  return 0;
}
