#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
map<long long, long long> mmp;
long long sum[maxn];
long long val[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> val[i], sum[i] = sum[i - 1] + val[i];
  long long ans = 0;
  mmp[0] = 1;
  for (int i = 1; i <= n; i++) {
    long long temp = 1;
    while (temp < 1e15) {
      ans += mmp[sum[i] - temp];
      temp *= k;
      if (k == 1) break;
      if (k == -1 && temp == 1) break;
    }
    mmp[sum[i]]++;
  }
  cout << ans << endl;
  return 0;
}
