#include<bits/stdc++.h>#define int long longusingnamespace std;constint maxn =1e5+5;int sum[maxn];
map <int,int> m;signedmain(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);int n, k;
cin >> n >> k;int all =0;for(int i =1; i <= n; i ++){
cin >> sum[i];
all +=abs(sum[i]);
sum[i]+= sum[i -1];}int ans =0, t =1;while(abs(t)<= all){
m.clear();
m[0]++;for(int i =1; i <= n; i ++){
ans += m[sum[i]- t];
m[sum[i]]++;}
t *= k;if(t ==1)break;}
cout << ans;return0;}
#include<iostream>#define int long longusingnamespace std;constint maxn =100000+5;int a[maxn], sum[maxn];signedmain(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);int n;while(cin >> n && n){for(int i =1; i <= n; i ++){
a[i]= sum[i]=0;}for(int i =1; i <= n; i ++){int l, r;
cin >> l >> r;
a[l]++;
a[r +1]--;}for(int i =1; i <= n; i ++){
sum[i]= sum[i -1]+ a[i];}for(int i =1; i < n; i ++){
cout << sum[i]<<' ';}
cout << sum[n]<< endl;}return0;}