#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
int a[100010], b[100010];
long long dex, x, k, n, p, ans;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  p = 1;
  while (abs(p) < 1e15) {
    mp.clear();
    dex = 0;
    mp[0] = 1;
    for (int i = 0; i < n; i++) {
      dex += a[i];
      ans += mp[dex - p];
      mp[dex]++;
    }
    p *= k;
    if (p == 1) break;
  }
  cout << ans << endl;
}
