#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
int n;
long long k, ans, x;
map<long long, int> mp;
int main() {
  scanf("%d", &n);
  scanf("%lld", &k);
  ans = 0;
  mp[0] = 1;
  long long acc = 0;
  for (int i = 1; i < (int)n + 1; i++) {
    scanf("%lld", &x);
    acc += x;
    for (long long pot = 1, j = 0; abs(pot) <= 1e14; pot *= k, j++) {
      if ((k == 1 && j == 1) || (k == -1 && j == 2)) break;
      ans += mp[acc - pot];
    }
    mp[acc]++;
  }
  printf("%lld\n", ans);
}
