#include <bits/stdc++.h>
using namespace std;
long long n, m, k, x;
bool compb(char a, char b) { return a > b; }
bool compm(char a, char b) { return a < b; }
int main() {
  cin >> n >> k;
  vector<long long> mas(n + 1, 0);
  map<long long, long long> ma;
  ma[0]++;
  long long res = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> mas[i];
    mas[i] += mas[i - 1];
    if (k == 1)
      res += ma[mas[i] - 1];
    else if (k == -1)
      res += ma[mas[i] - 1] + ma[mas[i] + 1];
    else {
      long long ex = 1;
      while (ex <= 1e15) {
        res += ma[mas[i] - ex];
        ex *= k;
      }
    }
    ma[mas[i]]++;
  }
  cout << res;
  return 0;
}
