#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const long long INF = 1e14 + 5;
long long sum;
int a[maxn];
map<long long, int> mp;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  long long pow = 1, ans = 0;
  while (abs(pow) < INF) {
    mp.clear();
    mp[0] = 1;
    sum = 0;
    for (int i = 1; i <= n; i++) {
      sum = sum + a[i];
      ans += mp[sum - pow];
      mp[sum]++;
    }
    pow = pow * k;
    if (pow == 1) break;
  }
  cout << ans << endl;
  return 0;
}
