#include <bits/stdc++.h>
using namespace std;
void sol();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  long long ml = 1, ans = 0;
  vector<int> ls(n);
  map<long long, int> pre, mp;
  mp[0] = 1;
  vector<long long> an;
  while (ml < 1e15) {
    if (!pre[ml])
      an.push_back(ml), pre[ml] = 1;
    else
      break;
    ml *= k;
    if ((ml > 1e15 || -ml > 1e15) || (ml % k != 0)) break;
  }
  for (int &x : ls) cin >> x;
  long long sm = 0ll;
  for (int x : ls) {
    sm += x;
    for (long long y : an)
      if (mp[sm - y]) ans += mp[sm - y];
    mp[sm]++;
  }
  cout << ans;
}
