#include <bits/stdc++.h>
struct Hash {
  long long key;
  int cnt;
  Hash *next;
  void set(long long k) {
    key = k;
    cnt = 1;
    next = NULL;
  }
};
Hash *hashtale[100007];
void create() {
  for (int i = 0; i < 100007; i++) hashtale[i] = NULL;
}
int search(long long k) {
  int l = (k % 100007 + 100007) % 100007;
  Hash *tmp = hashtale[l];
  if (tmp == NULL) return 0;
  while (tmp != NULL && tmp->key != k) tmp = tmp->next;
  if (tmp == NULL)
    return 0;
  else
    return tmp->cnt;
}
void insert(long long k) {
  int l = (k % 100007 + 100007) % 100007;
  Hash *tmp = hashtale[l];
  if (search(k) == 0) {
    Hash *node = new Hash;
    node->set(k);
    if (tmp == NULL)
      hashtale[l] = node;
    else {
      while (tmp->next != NULL) tmp = tmp->next;
      tmp->next = node;
    }
  } else {
    while (tmp->key != k) tmp = tmp->next;
    tmp->cnt++;
  }
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  create();
  long long sum = 0;
  int tmp;
  long long ans = 0;
  insert(0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    sum += tmp;
    insert(sum);
    if (k == 1)
      ans += search(sum - 1);
    else if (k == -1)
      ans += search(sum - 1) + search(sum + 1);
    else {
      for (long long p = 1; p <= 2e14; p *= k) ans += search(sum - p);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
