#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma warning(disable : 4018)
void b_example() {
  int affection[100000 + 1];
  map<long long, int> exist_sum;
  int chemicals_count, k;
  cin >> chemicals_count >> k;
  for (int i = 1; i <= chemicals_count; i++) cin >> affection[i];
  long long ans_count = 0;
  for (long long p = 1; abs(p) < 1e15;) {
    exist_sum.clear();
    exist_sum[0] = 1;
    long long sum = 0;
    for (int i = 1; i <= chemicals_count; i++) {
      sum += affection[i];
      ans_count += exist_sum[sum - p];
      exist_sum[sum]++;
    }
    p *= k;
    if (p == 1) break;
  }
  cout << ans_count << endl;
}
int main() {
  b_example();
  return 0;
}
