#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 3e6;
const long long mod = 1e9 + 7;
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
int n;
int a[maxn];
long long k, ans, p = 1;
long long solve() {
  long long sum = 0, res = 0;
  map<long long, int> mp;
  mp.clear();
  mp[0] = 1;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    if (mp.count(sum - p)) res += mp[sum - p];
    mp[sum]++;
  }
  return res;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  while (abs(p) < 1e15) {
    ans += solve();
    p = p * k;
    if (p == 1) break;
  }
  cout << ans;
  return (0);
}
