#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  {
    long long int n, k;
    cin >> n >> k;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    ;
    long long int ans = 0;
    long long int p = 1;
    long long int cnt = 0;
    while (p <= 1e14) {
      map<long long int, long long int> h;
      long long int c = 0;
      cnt++;
      for (long long int i = 0; i < n; i++) {
        c += a[i];
        if (c == p) ans++;
        ans += h[c - p];
        h[c]++;
      }
      p = p * k;
      if (k == 1 and cnt == 1) {
        break;
      }
      if (k == -1 and cnt == 2) {
        break;
      }
    }
    cout << ans;
  }
}
