	import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.ObjectInputStream.GetField;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

	public class Q1 {

		static long MOD = 1000000007;
		static boolean b[], b1[];
		static ArrayList<Integer>[] amp, pa;
		static ArrayList<Graph>[] amp1;
		static int sum[],dist[],cnt[],arr[],start[],color[],parent[],prime[];
		static long ans = 0,k;
		static int p = 0;
		static FasterScanner sc = new FasterScanner();
		static Queue<Integer> q = new LinkedList<>();
		static PriorityQueue<Integer> pq;
		static BufferedWriter log;
		static HashSet<Integer> hs;
		static HashMap<String,Integer> hm;
		static Pair prr[];
		static long parent1[],parent2[],size[][],size1[],size2[],arr1[];
		public static void main(String[] args) throws Exception {
	    	new Thread(null, new Runnable() {
				public void run() {
					try {
						soln();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "1", 1 << 26).start();
		}
	 static	class Node{
			int x,len,val;
			Node(int x, int len, int val){
				this.x = x;
				this.len = len;
				this.val = val;
			}
		}

		static int MAX = 2000000;
		StringBuilder sb = new StringBuilder();
		static String str;
		public static void soln() throws IOException {
			log = new BufferedWriter(new OutputStreamWriter(System.out));
			p = sc.nextInt();
			k = sc.nextLong();
			arr1 = sc.nextLongArray(p);
			ArrayList<Long> amp = new ArrayList<>();
			amp.add(1L);
			int a = (int)k ;
			while(k<1000000000000000L){
				amp.add(k);
				k*=a;
			}
			//System.out.println(amp);
			for(long i:amp){
				ans += getSum(i);
			//	System.out.println(ans);
			}
			System.out.println(ans);
			log.close();
		}
		static int getSum(long key){
			HashMap<Long,Integer> hm = new HashMap<>();
			long sum = 0;
			int cnt = 0;
			hm.put(0L, 1);
			for(int i = 0; i< p; i++){
				sum+=arr1[i];
				if(hm.containsKey(sum-key)){
					cnt+=hm.get(sum-key);
				}
				if(hm.containsKey(sum)) hm.put(sum, hm.get(sum)+1);
				else hm.put(sum, 1);
			}
			return cnt;
		}
		static void dfs(int x){
			b[x] = false;
			b1[x] = true;
			System.out.println(pa[x]);
			for(int e:pa[x]){
				if(!b1[e]){
					dfs(e);
				}
			}
		}
		public static void bfs(int x){
		b[x] = true;
		q = new LinkedList<>();
		dist[x] = 0;
		q.add(x);
		while(!q.isEmpty()){
			int y = q.poll();
			for(int i = 0;i<amp[y].size();i++) {
				if(!b[amp[y].get(i)]){
					q.add(amp[y].get(i));
					b[amp[y].get(i)] = true;
					dist[amp[y].get(i)] = dist[y]+1;
				}
			}
		}
		}
		public static void seive(int n){
			b = new boolean[(n+1)];
			Arrays.fill(b, true);
			b[1] = false;
			for(int i = 2;i*i<=n;i++){
				if(b[i]){
					for(int p = 2*i;p<=n;p+=i){
						b[p] = false;
						prime[p] = i;
					}
				}
			}
			for(int i = 2;i<=n;i++){
				if(b[i]) prime[i] = i;
			}
		}
		long sum1 = 0;
		public static long recur1(long n){
			if(n==0) return 0;
			if(n==1) return 1;
			return 1+2*recur1(n/2);
		}

		static class Graph{
			int vertex;
			int weight;
			Graph(int v, int w){
				vertex = v;
				weight = w;
			}
		}
		static class Pair implements Comparable<Pair> {
			int u;
			int v;
			public Pair(int u, int v) {
				this.u = u;
				this.v = v;
			}

			public int hashCode() {
				int hu = (int) (u ^ (u >>> 32));
				int hv = (int) (v ^ (v >>> 32));
				return 31*hu + hv;
			}

			public boolean equals(Object o) {
				Pair other = (Pair) o;
				return (u == other.u && v == other.v);
			}

			public int compareTo(Pair other) {
				return Integer.compare(u, other.u) != 0 ? (Integer.compare(u, other.u)) : (Integer.compare(v, other.v));
			}

			public String toString() {
				return "[u=" + u + ", v=" + v + "]";
			}
		}

		public static void buildGraph(int n){
			for(int i =0;i<n;i++){
				int x = sc.nextInt(), y = sc.nextInt();
				amp[--x].add(--y);
				amp[y].add(x);
			}
		}

		public static int getParent(int x){
			while(parent[x]!=x){
				parent[ x] = parent[(int) parent[ x]];
				x = parent[ x];
			}
			return x;
		}
		static long min(long a, long b, long c){
			if(a<b && a<c) return a;
			if(b<c) return b;
			return c;
		}
		/*

		static class Pair3{
			int x, y ,z;
			Pair3(int x, int y, int z){
				this.x = x;
				this.y = y;
				this.z = z;
			}
		}*/
		static int sum(int n){
			String str = Integer.toString(n);
			int cnt = 0;
			for(int i = 0; i< str.length();i++){
				cnt+=(str.charAt(i)-'0');
			}
			return cnt;
		}
		 static void KMPSearch(String pat, String txt)
		    {
		        int M = pat.length();
		        int N = txt.length();

		        // create lps[] that will hold the longest
		        // prefix suffix values for pattern
		        int lps[] = new int[M];
		        int j = 0;  // index for pat[]

		        // Preprocess the pattern (calculate lps[]
		        // array)
		        computeLPSArray(pat,M,lps);

		        int i = 0;  // index for txt[]
		        while (i < N)
		        {
		            if (pat.charAt(j) == txt.charAt(i))
		            {
		                j++;
		                i++;
		            }
		            if (j == M)
		            {
		               // parent.add((i-j));
		                j = lps[j-1];
		            }

		            // mismatch after j matches
		            else if (i < N && pat.charAt(j) != txt.charAt(i))
		            {
		                // Do not match lps[0..lps[j-1]] characters,
		                // they will match anyway
		                if (j != 0)
		                    j = lps[j-1];
		                else
		                    i = i+1;
		            }
		        }
		    }
		 static void computeLPSArray(String pat, int M, int lps[])
		    {
		        // length of the previous longest prefix suffix
		        int len = 0;
		        int i = 1;
		        lps[0] = 0;  // lps[0] is always 0

		        // the loop calculates lps[i] for i = 1 to M-1
		        while (i < M)
		        {
		            if (pat.charAt(i) == pat.charAt(len))
		            {
		                len++;
		                lps[i] = len;
		                i++;
		            }
		            else  // (pat[i] != pat[len])
		            {
		                // This is tricky. Consider the example.
		                // AAACAAAA and i = 7. The idea is similar
		                // to search step.
		                if (len != 0)
		                {
		                    len = lps[len-1];

		                    // Also, note that we do not increment
		                    // i here
		                }
		                else  // if (len == 0)
		                {
		                    lps[i] = len;
		                    i++;
		                }
		            }
		        }
		    }
		private static void permutation(String prefix, String str) {
		    int n = str.length();
		    if (n == 0); //hs.add(prefix);
		    else {
		        for (int i = 0; i < n; i++)
		            permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
		    }
		}
		public static char give(char c1,char c2){
			if(c1!='a' && c2!='a') return 'a';
			if(c1!='b' && c2!='b') return 'b';
			return 'c';
		}

		public static void buildTree(int n){
			int arr[] = sc.nextIntArray(n);
			for(int i = 0;i<n;i++){
				int x = arr[i]-1;
				amp[i+1].add(x);
				amp[x].add(i+1);
			}
		}

		static class SegmentTree {
			long st[];
			long lazy[];

			SegmentTree(int n) {
				int size = 4 * n;
				st = new long[size];
				//lazy = new long[size];
				//build(0, n - 1, 1);
			}

			/*long[] build(int ss, int se, int si) {
				if (ss == se) {
					st[si][0] = 1;
					st[si][1] = 1;
					st[si][2] = 1;
					return st[si];
				}
				int mid = (ss + se) / 2;
				long a1[] = build(ss, mid, si * 2), a2[] = build(mid + 1, se,
						si * 2 + 1);
				long ans[] = new long[3];
				if (arr[mid] < arr[mid + 1]) {
					ans[1] = Math.max(a2[1], Math.max(a1[1], a1[2] + a2[0]));
					if (a1[1] == (mid - ss + 1))
						ans[0] = ans[1];
					else
						ans[0] = a1[0];
					if (a2[2] == (se - mid))
						ans[2] = ans[1];
					else
						ans[2] = a2[2];
				} else {
					ans[1] = Math.max(a1[1], a2[1]);
					ans[0] = a1[0];
					ans[2] = a2[2];
				}
				st[si] = ans;
				return st[si];
			}*/

			void update(int si, int ss, int se, int idx, int val) {
				if (ss == se) {
					arr[idx] += val;
					st[si]+=val;
				}
				else {
					int mid = (ss + se) / 2;
					if(ss <= idx && idx <= mid)
			        {
			             update(2*si, ss, mid, idx, val);
			        }
			        else
			        { update(2*si+1, mid+1, se, idx, val);
			        }
					st[si] = st[2*si]+st[2*si+1];
				}
			}
			long get(int qs, int qe, int ss, int se, int si){
				if(qs>se || qe<ss) return 0;
				if (qs <= ss && qe >= se) {
					return st[si];
				}
				int mid = (ss+se)/2;
				return get(qs, qe, ss, mid, si * 2)+get(qs, qe, mid + 1, se, si * 2 + 1);
			}
			void updateRange(int node, int start, int end, int l, int r, int val)
			{
			    if(lazy[node] != 0)
			    {
			        // This node needs to be updated
			        st[node] += (end - start + 1) * lazy[node];    // Update it
			        if(start != end)
			        {
			            lazy[node*2] += lazy[node];                  // Mark child as lazy
			            lazy[node*2+1] += lazy[node];                // Mark child as lazy
			        }
			        lazy[node] = 0;                                  // Reset it
			    }
			    if(start > end || start > r || end < l)              // Current segment is not within range [l, r]
			        return;
			    if(start >= l && end <= r)
			    {
			        // Segment is fully within range
			        st[node] += (end - start + 1) * val;
			        if(start != end)
			        {
			            // Not leaf node
			            lazy[node*2] += val;
			            lazy[node*2+1] += val;
			        }
			        return;
			    }
			    int mid = (start + end) / 2;
			    updateRange(node*2, start, mid, l, r, val);        // Updating left child
			    updateRange(node*2 + 1, mid + 1, end, l, r, val);   // Updating right child
			    st[node] = st[node*2] + st[node*2+1];        // Updating root with max value
			}

			int queryRange(int node, int start, int end, int l, int r)
			{
			    if(start > end || start > r || end < l)
			        return 0;         // Out of range
			    if(lazy[node] != 0)
			    {
			        // This node needs to be updated
			        st[node] += (end - start + 1) * lazy[node];            // Update it
			        if(start != end)
			        {
			            lazy[node*2] += lazy[node];         // Mark child as lazy
			            lazy[node*2+1] += lazy[node];    // Mark child as lazy
			        }
			        lazy[node] = 0;                 // Reset it
			    }
			    if(start >= l && end <= r)             // Current segment is totally within range [l, r]
			        return (int) st[node];
			    int mid = (start + end) / 2;
			    int p1 = queryRange(node*2, start, mid, l, r);         // Query left child
			    int p2 = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child
			    return (p1 + p2);
			}
			void print() {
				for (int i = 0; i < st.length; i++) {
					System.out.print(st[i]+" ");
				}
				System.out.println();
			}
		}
		static int convert(int x){
			int cnt = 0;
			String str = Integer.toBinaryString(x);
			//System.out.println(str);
			for(int i = 0;i<str.length();i++){
				if(str.charAt(i)=='1'){
					cnt++;
				}
			}
			int ans = (int) Math.pow(3, 6-cnt);
			return ans;
		}
		static class Node2{
			Node2 left = null;
			Node2 right = null;
			Node2 parent = null;
			int data;
		}
		static class BinarySearchTree{
			Node2 root = null;
			int height = 0;
			int max = 0;
			int cnt = 1;
			ArrayList<Integer> parent = new ArrayList<>();
			HashMap<Integer, Integer> hm = new HashMap<>();
			public void insert(int x){
				Node2 n = new Node2();
				n.data = x;
				if(root==null){
					root = n;
				}
				else{
					Node2 temp = root,temp2 = null;
					while(temp!=null){
						temp2 = temp;
						if(x>temp.data) temp = temp.right;
						else temp = temp.left;
					}
					if(x>temp2.data) temp2.right = n;
					else temp2.left = n;
					n.parent = temp2;
					parent.add(temp2.data);
				}
			}
			public Node2 getSomething(int x, int y, Node2 n){
				if(n.data==x || n.data==y) return n;
				else if(n.data>x && n.data<y) return n;
				else if(n.data<x && n.data<y) return getSomething(x,y,n.right);
				else return getSomething(x,y,n.left);
			}
			public Node2 search(int x,Node2 n){
				if(x==n.data){
					max = Math.max(max, n.data);
					return n;
				}
				if(x>n.data){
					max = Math.max(max, n.data);
					return search(x,n.right);
				}
				else{
					max = Math.max(max, n.data);
					return search(x,n.left);
				}
			}
			public int getHeight(Node2 n){
				if(n==null) return 0;
				height = 1+ Math.max(getHeight(n.left), getHeight(n.right));
				return height;
			}
		}
		static long findDiff(long[] arr, long[] brr, int m){
			int i = 0, j = 0;
			long fa = 1000000000000L;
			while(i<m && j<m){
				long x = arr[i]-brr[j];
				if(x>=0){
					if(x<fa) fa = x;
					j++;
				}
				else{
					if((-x)<fa) fa = -x;
					i++;
				}
			}
			return fa;
		}
		public static long max(long x, long y, long z){
			if(x>=y && x>=z) return x;
			if(y>=x && y>=z) return y;
			return z;
		}

		static long modInverse(long a, long mOD2){
		            return  power(a, mOD2-2, mOD2);
		}
		static long power(long x, long y, long m)
		{
		    if (y == 0)
		        return 1;
		    long p = power(x, y/2, m) % m;
		    p = (p * p) % m;

		    return (y%2 == 0)? p : (x * p) % m;
		}
		static long power2(long x,BigInteger y,long m){
			long ans = 1;
			BigInteger two = new BigInteger("2");
			while(y.compareTo(BigInteger.ZERO)>0){
				if(y.getLowestSetBit()==y.bitCount()){
					x = (x*x)%MOD;
					y = y.divide(two);
				}
				else{
					ans = (ans*x)%MOD;
					y = y.subtract(BigInteger.ONE);
				}
			}
			return ans;
		}
		static BigInteger power2(BigInteger x, BigInteger y, BigInteger m){
			BigInteger ans = new BigInteger("1");
			BigInteger one  = new BigInteger("1");
			BigInteger two  = new BigInteger("2");
			BigInteger zero  = new BigInteger("0");
			while(y.compareTo(zero)>0){
				//System.out.println(y);
				if(y.mod(two).equals(one)){
					ans = ans.multiply(x).mod(m);
					y = y.subtract(one);
				}
				else{
					x = x.multiply(x).mod(m);
					y = y.divide(two);
				}
			}
			return ans;
		}
		static BigInteger power(BigInteger x, BigInteger y, BigInteger m)
		{
		    if (y.equals(0))
		        return (new BigInteger("1"));
		    BigInteger p = power(x, y.divide(new BigInteger("2")), m).mod(m);
		    p = (p.multiply(p)).mod(m);

		    return (y.mod(new BigInteger("2")).equals(0))? p : (p.multiply(x)).mod(m);
		}
		static long d,x,y;
		public static void extendedEuclidian(long a, long b){
			if(b == 0) {
		        d = a;
		        x = 1;
		        y = 0;
		    }
		    else {
		        extendedEuclidian(b, a%b);
		        int temp = (int) x;
		        x = y;
		        y = temp - (a/b)*y;
		    }
		}

		public static long gcd(long n, long m){
			if(m!=0) return gcd(m,n%m);
			else return n;
		}

		static BufferedReader reader;
	    static StringTokenizer tokenizer;
	    static PrintWriter writer;

		public static class FasterScanner {
			private byte[] buf = new byte[1024];
			private int curChar;
			private int numChars;

			public int read() {
				if (numChars == -1)
					throw new InputMismatchException();
				if (curChar >= numChars) {
					curChar = 0;
					try {
						numChars = System.in.read(buf);
					} catch (IOException e) {
						throw new InputMismatchException();
					}
					if (numChars <= 0)
						return -1;
				}
				return buf[curChar++];
			}

			public String nextLine() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isEndOfLine(c));
				return res.toString();
			}

			public String nextString() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isSpaceChar(c));
				return res.toString();
			}

			public long nextLong() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				int sgn = 1;
				if (c == '-') {
					sgn = -1;
					c = read();
				}
				long res = 0;
				do {
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = read();
				} while (!isSpaceChar(c));
				return res * sgn;
			}

			public int nextInt() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				int sgn = 1;
				if (c == '-') {
					sgn = -1;
					c = read();
				}
				int res = 0;
				do {
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = read();
				} while (!isSpaceChar(c));
				return res * sgn;
			}

		    public int[] nextIntArray(int n) {
		        return nextIntArray(n, 0);
		    }

		    public int[] nextIntArray(int n, int off) {
		    	int[] arr = new int[n + off];
		    	for (int i = 0; i < n; i++) {
		    		arr[i + off] = nextInt();
		    	}
		    	return arr;
		    }

		    public long[] nextLongArray(int n) {
		    	return nextLongArray(n, 0);
		    }

			public long[] nextLongArray(int n, int off) {
			    long[] arr = new long[n + off];
			    for (int i = 0; i < n; i++) {
			        arr[i + off] = nextLong();
			    }
			    return arr;
			}

		    private boolean isSpaceChar(int c) {
				return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
			}

			private boolean isEndOfLine(int c) {
				return c == '\n' || c == '\r' || c == -1;
			}
		}
	}


import java.io.*;
import java.util.*;

public class C {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt();
        long k  =fs.nextInt();
        TreeSet<Long> pow = new TreeSet<>();
        pow.add(1l);
        long add = k;
        while(add != 1 && add <= (long)1e18 && add >= -(long)1e18) {
            pow.add(add);
            add *= k;
        }
//        System.out.printf("%s\n", pow.toString());
        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = fs.nextLong();
        }
        long res = 0;
        for(Long p : pow) {
            TreeSet<Long> has = new TreeSet<>();
            long sum = 0;
            for(int i = 0; i < n; i++) {
                sum += a[i];
                if(sum == p) res++;

                if(has.contains(sum - p)) res++;

                has.add(sum);
            }
        }

        out.println(res);
        out.close();
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

    public double nextDouble() {return Double.parseDouble(next());}

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


import java.io.*;
import java.util.*;

public class C {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt();
        long k  =fs.nextInt();
        TreeSet<Long> pow = new TreeSet<>();
        pow.add(1l);
        long add = k;
        while(add != 1 && add <= (long)1e18 && add >= -(long)1e18) {
            pow.add(add);
            add *= k;
        }
//        System.out.printf("%s\n", pow.toString());
        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = fs.nextLong();
        }
        long res = 0;
        for(Long p : pow) {
            HashMap<Long, Integer> has = new HashMap<>();
            long sum = 0;
            for(int i = 0; i < n; i++) {
//                if(a[i] == p) res++;
                sum += a[i];
                if(sum == p) res++;

                if(has.containsKey(sum - p)) res += has.get(sum - p);
                if(has.containsKey(sum)) has.put(sum, has.get(sum)+1);
                else has.put(sum, 1);
            }
        }

        out.println(res);
        out.close();
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

    public double nextDouble() {return Double.parseDouble(next());}

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


import java.io.*;
import java.util.*;

public class C {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt();
        long k  =fs.nextInt();
        TreeSet<Long> pow = new TreeSet<>();
        pow.add(1l);
        long add = k;
        while(add != 1 && add <= (long)1e18 && add >= -(long)1e18) {
            pow.add(add);
            add *= k;
        }

        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = fs.nextLong();
        }
        long res = 0;
        for(Long p : pow) {
            TreeSet<String> seen = new TreeSet<>();
            System.out.printf("%d\n", p);
            int i = 0, j = 0;
            long curSum = 0;
            if(p > 0) {
                while(j < n) {
                    curSum += a[j];
                    //exceed sum?
                    if(curSum == p) {
                        res++;
                    }
                    while(i < n && (curSum > p || j == n-1)) {
                        curSum -= a[i++];
                        if(curSum == p) res++;
                    }
                    j++;
                }
            } else {
                while(j < n) {
                    curSum += a[j];
                    //below sum?
                    if(curSum == p) res++;
                    while(i < n && (curSum < p || j == n-1)) {
                        curSum -= a[i++];
                        if(curSum == p) res++;
                    }
                    j++;
                }
            }
        }

        out.println(res);
        out.close();
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

    public double nextDouble() {return Double.parseDouble(next());}

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


import java.io.*;
import java.util.*;

public class C {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt();
        long k  =fs.nextInt();
        TreeSet<Long> pow = new TreeSet<>();
        pow.add(1l);
        long add = k;
        while(add <= (long)1e18 && add >= -(long)1e18) {
            pow.add(add);
            add *= k;
        }

        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = fs.nextLong();
        }
        long res = 0;
        for(Long p : pow) {
            TreeSet<String> seen = new TreeSet<>();
//            System.out.printf("%d\n", p);
            int i = 0, j = 0;
            long curSum = 0;
            if(p > 0) {
                while(j < n) {
                    curSum += a[j];
                    //exceed sum?
                    while(i < n && (curSum >= p || j == n-1)) {
                        if(curSum == p) {
                            res++;
                        }
                        curSum -= a[i++];
                    }
                    j++;
                }
            } else {
                while(j < n) {
                    curSum += a[j];
                    //below sum?
                    while(i < n && (curSum <= p || j == n-1)) {
                        if(curSum == p) {
                            res++;
                        }
                        curSum -= a[i++];
                    }
                    j++;
                }
            }
        }

        out.println(res);
        out.close();
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

    public double nextDouble() {return Double.parseDouble(next());}

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


import java.io.*;
import java.util.*;

public class C {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt();
        long k  =fs.nextInt();
        TreeSet<Long> pow = new TreeSet<>();
        pow.add(1l);
        long add = k;
        while(add != 1 && add <= (long)1e18 && add >= -(long)1e18) {
            pow.add(add);
            add *= k;
        }

        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = fs.nextLong();
        }
        long res = 0;
        for(Long p : pow) {
            TreeSet<String> seen = new TreeSet<>();
//            System.out.printf("%d\n", p);
            int i = 0, j = 0;
            long curSum = 0;
            if(p > 0) {
                while(j < n) {
                    curSum += a[j];
                    //exceed sum?
                    if(curSum == p) {
                        res++;
                    }
                    while(i < n && (curSum > p || j == n-1)) {
                        curSum -= a[i++];
                        if(curSum == p) res++;
                    }
                    j++;
                }
            } else {
                while(j < n) {
                    curSum += a[j];
                    //below sum?
                    if(curSum == p) res++;
                    while(i < n && (curSum < p || j == n-1)) {
                        curSum -= a[i++];
                        if(curSum == p) res++;
                    }
                    j++;
                }
            }
        }

        out.println(res);
        out.close();
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

    public double nextDouble() {return Double.parseDouble(next());}

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

import java.io.*;
import java.util.*;

public class C {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        long start = System.currentTimeMillis();
        int n = fs.nextInt();
        long k  =fs.nextInt(), s = 0;
        TreeSet<Long> pow = new TreeSet<>();
        pow.add(1l);
        long add = k;
        while(add != 1 && add <= (long)1e18 && add >= -(long)1e18) {
            pow.add(add);
            add *= k;
        }
//        System.out.printf("%s\n", pow.toString());
        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = fs.nextLong();
            s += a[i];
        }
        long res = 0;

        long sum = 0;
        //keeping a single hashmap instead of remaking it n times will probably make it faster.
        HashMap<Long, Integer> has = new HashMap<>();
        for(int i = 0; i < n; i++) {
            sum += a[i];
            for(Long p : pow) {
                if(sum == p) res++;
                if(has.containsKey(sum - p)) res += has.get(sum-p);
            }

            if(has.containsKey(sum)) has.put(sum, has.get(sum)+1);
            else has.put(sum, 1);
        }

        out.println(res);
//        out.println(System.currentTimeMillis() - start);
        out.close();
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
//            br = new BufferedReader(new FileReader("testdata.out"));
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

    public double nextDouble() {return Double.parseDouble(next());}

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


import java.io.*;
import java.util.*;

public class C {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt();
        long k  =fs.nextInt();
        TreeSet<Long> pow = new TreeSet<>();
        pow.add(1l);
        long add = k;
        while(add <= (long)1e18 && add >= -(long)1e18) {
            pow.add(add);
            add *= k;
        }

        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = fs.nextLong();
        }
        long res = 0;
        for(Long p : pow) {
            TreeSet<String> seen = new TreeSet<>();
//            System.out.printf("%d\n", p);
            int i = 0, j = 0;
            long curSum = 0;
            if(p > 0) {
                while(j < n) {
                    curSum += a[j];
                    //exceed sum?
                    if(curSum == p) {
                        res++;
                    }
                    while(i < n && (curSum > p || j == n-1)) {
                        curSum -= a[i++];
                        if(curSum == p) res++;
                    }
                    j++;
                }
            } else {
                while(j < n) {
                    curSum += a[j];
                    //below sum?
                    if(curSum == p) res++;
                    while(i < n && (curSum < p || j == n-1)) {
                        curSum -= a[i++];
                        if(curSum == p) res++;
                    }
                    j++;
                }
            }
        }

        out.println(res);
        out.close();
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

    public double nextDouble() {return Double.parseDouble(next());}

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


import java.io.*;
import java.util.*;

public class C {
    public static void main(String[] args) throws Exception {
        FastScannerC fs = new FastScannerC();
        PrintWriter out = new PrintWriter(System.out);

        int n = fs.nextInt();
        long k  =fs.nextInt();
        TreeSet<Long> pow = new TreeSet<>();
        pow.add(1l);
        long add = k;
        while(add != 1 && add <= (long)1e18 && add >= -(long)1e18) {
            pow.add(add);
            add *= k;
        }
//        System.out.printf("%s\n", pow.toString());
        long[] a = new long[n];
        for(int i = 0; i < n; i++) {
            a[i] = fs.nextLong();
        }
        long res = 0;
        for(Long p : pow) {
            TreeMap<Long, Integer> has = new TreeMap<>();
            long sum = 0;
            for(int i = 0; i < n; i++) {
//                if(a[i] == p) res++;
                sum += a[i];
                if(sum == p) res++;

                if(has.containsKey(sum - p)) res += has.get(sum - p);
                if(has.containsKey(sum)) has.put(sum, has.get(sum)+1);
                else has.put(sum, 1);
            }
        }

        out.println(res);
        out.close();
    }
}

class FastScannerC {
    BufferedReader br;
    StringTokenizer st;

    public FastScannerC() {
        try	{
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        } catch (Exception e){e.printStackTrace();}
    }

    public String next() {
        if (st.hasMoreTokens())	return st.nextToken();
        try {st = new StringTokenizer(br.readLine());}
        catch (Exception e) {e.printStackTrace();}
        return st.nextToken();
    }

    public int nextInt() {return Integer.parseInt(next());}

    public long nextLong() {return Long.parseLong(next());}

    public double nextDouble() {return Double.parseDouble(next());}

    public String nextLine() {
        String line = "";
        try {line = br.readLine();}
        catch (Exception e) {e.printStackTrace();}
        return line;
    }

    public Integer[] nextIntegerArray(int n) {
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        return a;
    }

    public char[] nextCharArray() {
        return nextLine().toCharArray();
    }
}


import java.io.*;
import java.util.*;

public class Main {
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	// ======================================================
	void solve() throws IOException {
		int n = rI();
		long k = rI();
		int[] a = rA(n);
		HashMap<Long, Long> suffIx = new HashMap<Long, Long>();
		ArrayList<Long> kPow = new ArrayList<Long>();
		long flag = 1;
		if (k == 1 || k == -1) {
			kPow.add(k);
		} else {
			while (flag <= (long) 100 * 1000 * 1000 * 1000 * 1000 && flag >= (long) -100 * 1000 * 1000 * 1000 * 1000) {
				flag *= k;
				kPow.add(flag);
			}
		}
		kPow.add((long)1);
		long sum = summ(a);
		long[] preFix = new long[n];
		flag = 0;
		for (int i = 0; i < n; i++) {
			preFix[i] = flag + a[i];
			flag = preFix[i];
		}
		for (int i = 0; i < n; i++) {
			suffIx.put(preFix[i], suffIx.getOrDefault(preFix[i], (long) 0) + 1);
		}
		long ans = 0;
		for (long i : kPow) {
			ans += suffIx.getOrDefault(i, (long) 0);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < kPow.size(); j++) {
				long d = kPow.get(j);
				long def = preFix[i] + d;
				ans += suffIx.getOrDefault(def, (long) 0);

			}
			if (suffIx.get(preFix[i]) != null) {
				if (suffIx.get(preFix[i]) == 1) {
					suffIx.remove(preFix[i]);
				} else {
					suffIx.put(preFix[i], suffIx.get(preFix[i]) - 1);
				}
			}
		}
		out.println(ans);

	}

	// ===========================================================================
	long summ(int[] a) {
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans += a[i];
		}
		return ans;
	}

	long summToIndex(int[] a, int index) {
		long ans = 0;
		for (int i = 0; i < index; i++) {
			ans += a[i];
		}
		return ans;
	}

	int minInt(int... values) {
		int min = Integer.MAX_VALUE;
		for (int value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	int maxInt(int... values) {
		int max = Integer.MIN_VALUE;
		for (int value : values) {
			max = Math.max(max, value);
		}
		return max;
	}

	long minLong(long... values) {
		long min = Long.MAX_VALUE;
		for (long value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	long maxLong(long... values) {
		long min = Long.MIN_VALUE;
		for (long value : values) {
			min = Math.max(min, value);
		}
		return min;
	}

	// ==============================================================================

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	long maxA(int[] each) {
		long max = Integer.MIN_VALUE;
		for (int i = 0; i < each.length; i++) {
			if (each[i] > max) {
				max = each[i];

			}
		}
		return max;
	}

	long minA(long[] a) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	// ======================================================
	void solve() throws IOException {
		int n = rI();
		long k = rI();
		int[] a = rA(n);
		HashMap<Long, Long> suffIx = new HashMap<Long, Long>();
		ArrayList<Long> kPow = new ArrayList<Long>();
		long flag = 1;
		if (k == 1 || k == -1) {
			kPow.add(k);
		} else {
			while (flag <= (long) 100 * 1000 * 1000 * 1000 * 1000 && flag >= (long) -100 * 1000 * 1000 * 1000 * 1000) {
				flag *= k;
				kPow.add(flag);
			}
			kPow.add((long) 1);
		}

		long sum = summ(a);
		long[] preFix = new long[n];
		flag = 0;
		for (int i = 0; i < n; i++) {
			preFix[i] = flag + a[i];
			flag = preFix[i];
		}
		for (int i = 0; i < n; i++) {
			suffIx.put(preFix[i], suffIx.getOrDefault(preFix[i], (long) 0) + 1);
		}
		long ans = 0;
		for (long i : kPow) {
			ans += suffIx.getOrDefault(i, (long) 0);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < kPow.size(); j++) {
				long d = kPow.get(j);
				long def = preFix[i] + d;
				ans += suffIx.getOrDefault(def, (long) 0);

			}
			if (suffIx.get(preFix[i]) != null) {
				if (suffIx.get(preFix[i]) == 1) {
					suffIx.remove(preFix[i]);
				} else {
					suffIx.put(preFix[i], suffIx.get(preFix[i]) - 1);
				}
			}
		}
		out.println(ans);

	}

	// ===========================================================================
	long summ(int[] a) {
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans += a[i];
		}
		return ans;
	}

	long summToIndex(int[] a, int index) {
		long ans = 0;
		for (int i = 0; i < index; i++) {
			ans += a[i];
		}
		return ans;
	}

	int minInt(int... values) {
		int min = Integer.MAX_VALUE;
		for (int value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	int maxInt(int... values) {
		int max = Integer.MIN_VALUE;
		for (int value : values) {
			max = Math.max(max, value);
		}
		return max;
	}

	long minLong(long... values) {
		long min = Long.MAX_VALUE;
		for (long value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	long maxLong(long... values) {
		long min = Long.MIN_VALUE;
		for (long value : values) {
			min = Math.max(min, value);
		}
		return min;
	}

	// ==============================================================================

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	long maxA(int[] each) {
		long max = Integer.MIN_VALUE;
		for (int i = 0; i < each.length; i++) {
			if (each[i] > max) {
				max = each[i];

			}
		}
		return max;
	}

	long minA(long[] a) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	// ======================================================
	void solve() throws IOException {
		int n = rI();
		long k = rI();
		int[] a = rA(n);
		HashMap<Long, Long> suffIx = new HashMap<Long, Long>();
		ArrayList<Long> kPow = new ArrayList<Long>();
		long flag = 1;
		if (k == 1) {
			kPow.add(k);
		} else {
			if (k == -1) {
				kPow.add((long) 1);
				kPow.add((long) -1);

			} else
				while (flag <= (long) 100 * 1000 * 1000 * 1000 * 1000
						&& flag >= (long) -100 * 1000 * 1000 * 1000 * 1000) {
					flag *= k;
					kPow.add(flag);
				}
			kPow.add((long) 1);

		}
	}

	long sum = summ(a);
	long[] preFix = new long[n];flag=0;for(
	int i = 0;i<n;i++)
	{
		preFix[i] = flag + a[i];
		flag = preFix[i];
	}for(
	int i = 0;i<n;i++)
	{
		suffIx.put(preFix[i], suffIx.getOrDefault(preFix[i], (long) 0) + 1);
	}
	long ans = 0;for(
	long i:kPow)
	{
		ans += suffIx.getOrDefault(i, (long) 0);
	}for(
	int i = 0;i<n;i++)
	{
		for (int j = 0; j < kPow.size(); j++) {
			long d = kPow.get(j);
			long def = preFix[i] + d;
			ans += suffIx.getOrDefault(def, (long) 0);

		}
		if (suffIx.get(preFix[i]) != null) {
			if (suffIx.get(preFix[i]) == 1) {
				suffIx.remove(preFix[i]);
			} else {
				suffIx.put(preFix[i], suffIx.get(preFix[i]) - 1);
			}
		}
	}out.println(ans);

	}

	// ===========================================================================
	long summ(int[] a) {
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans += a[i];
		}
		return ans;
	}

	long summToIndex(int[] a, int index) {
		long ans = 0;
		for (int i = 0; i < index; i++) {
			ans += a[i];
		}
		return ans;
	}

	int minInt(int... values) {
		int min = Integer.MAX_VALUE;
		for (int value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	int maxInt(int... values) {
		int max = Integer.MIN_VALUE;
		for (int value : values) {
			max = Math.max(max, value);
		}
		return max;
	}

	long minLong(long... values) {
		long min = Long.MAX_VALUE;
		for (long value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	long maxLong(long... values) {
		long min = Long.MIN_VALUE;
		for (long value : values) {
			min = Math.max(min, value);
		}
		return min;
	}

	// ==============================================================================

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	long maxA(int[] each) {
		long max = Integer.MIN_VALUE;
		for (int i = 0; i < each.length; i++) {
			if (each[i] > max) {
				max = each[i];

			}
		}
		return max;
	}

	long minA(long[] a) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	// ======================================================
	void solve() throws IOException {
		int n = rI();
		long k = rI();
		int[] a = rA(n);
		HashMap<Long, Long> suffIx = new HashMap<Long, Long>();
		ArrayList<Long> kPow = new ArrayList<Long>();
		long flag = 1;
		if (k == 1 || k == -1) {
			kPow.add(k);
		} else {
			while (flag <= (long) 100 * 1000 * 1000 * 1000 * 1000 && flag >= (long) -100 * 1000 * 1000 * 1000 * 1000) {
				flag *= k;
				kPow.add(flag);
			}
		}
		long sum = summ(a);
		long[] preFix = new long[n];
		flag = 0;
		for (int i = 0; i < n; i++) {
			preFix[i] = flag + a[i];
			flag = preFix[i];
		}
		for (int i = 0; i < n; i++) {
			suffIx.put(preFix[i], suffIx.getOrDefault(preFix[i], (long) 0) + 1);
		}
		long ans = 0;
		for (long i : kPow) {
			ans += suffIx.getOrDefault(i, (long) 0);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < kPow.size(); j++) {
				long d = kPow.get(j);
				long def = preFix[i] + d;
				ans += suffIx.getOrDefault(def, (long) 0);

			}
			if (suffIx.get(preFix[i]) != null) {
				if (suffIx.get(preFix[i]) == 1) {
					suffIx.remove(preFix[i]);
				} else {
					suffIx.put(preFix[i], suffIx.get(preFix[i]) - 1);
				}
			}
		}
		out.println(ans);

	}

	// ===========================================================================
	long summ(int[] a) {
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans += a[i];
		}
		return ans;
	}

	long summToIndex(int[] a, int index) {
		long ans = 0;
		for (int i = 0; i < index; i++) {
			ans += a[i];
		}
		return ans;
	}

	int minInt(int... values) {
		int min = Integer.MAX_VALUE;
		for (int value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	int maxInt(int... values) {
		int max = Integer.MIN_VALUE;
		for (int value : values) {
			max = Math.max(max, value);
		}
		return max;
	}

	long minLong(long... values) {
		long min = Long.MAX_VALUE;
		for (long value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	long maxLong(long... values) {
		long min = Long.MIN_VALUE;
		for (long value : values) {
			min = Math.max(min, value);
		}
		return min;
	}

	// ==============================================================================

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	long maxA(int[] each) {
		long max = Integer.MIN_VALUE;
		for (int i = 0; i < each.length; i++) {
			if (each[i] > max) {
				max = each[i];

			}
		}
		return max;
	}

	long minA(long[] a) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	// ======================================================
	void solve() throws IOException {
		int n = rI();
		long k = rI();
		int[] a = rA(n);
		HashMap<Long, Long> suffIx = new HashMap<Long, Long>();
		ArrayList<Long> kPow = new ArrayList<Long>();
		long flag = 1;
		if (k == 1) {
			kPow.add(k);
		} else {
			if (k == -1) {
				kPow.add((long) 1);
				kPow.add((long) -1);

			} else {
				while (flag <= (long) 100 * 1000 * 1000 * 1000 * 1000
						&& flag >= (long) -100 * 1000 * 1000 * 1000 * 1000) {
					flag *= k;
					kPow.add(flag);
				}
				kPow.add((long) 1);

			}
		}
		long sum = summ(a);
		long[] preFix = new long[n];
		flag = 0;
		for (int i = 0; i < n; i++) {
			preFix[i] = flag + a[i];
			flag = preFix[i];
		}
		for (int i = 0; i < n; i++) {
			suffIx.put(preFix[i], suffIx.getOrDefault(preFix[i], (long) 0) + 1);
		}
		long ans = 0;
		for (long i : kPow) {
			ans += suffIx.getOrDefault(i, (long) 0);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < kPow.size(); j++) {
				long d = kPow.get(j);
				long def = preFix[i] + d;
				ans += suffIx.getOrDefault(def, (long) 0);

			}
			if (suffIx.get(preFix[i]) != null) {
				if (suffIx.get(preFix[i]) == 1) {
					suffIx.remove(preFix[i]);
				} else {
					suffIx.put(preFix[i], suffIx.get(preFix[i]) - 1);
				}
			}
		}
		out.println(ans);

	}

	// ===========================================================================
	long summ(int[] a) {
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans += a[i];
		}
		return ans;
	}

	long summToIndex(int[] a, int index) {
		long ans = 0;
		for (int i = 0; i < index; i++) {
			ans += a[i];
		}
		return ans;
	}

	int minInt(int... values) {
		int min = Integer.MAX_VALUE;
		for (int value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	int maxInt(int... values) {
		int max = Integer.MIN_VALUE;
		for (int value : values) {
			max = Math.max(max, value);
		}
		return max;
	}

	long minLong(long... values) {
		long min = Long.MAX_VALUE;
		for (long value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	long maxLong(long... values) {
		long min = Long.MIN_VALUE;
		for (long value : values) {
			min = Math.max(min, value);
		}
		return min;
	}

	// ==============================================================================

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	long maxA(int[] each) {
		long max = Integer.MIN_VALUE;
		for (int i = 0; i < each.length; i++) {
			if (each[i] > max) {
				max = each[i];

			}
		}
		return max;
	}

	long minA(long[] a) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	// ======================================================
	void solve() throws IOException {
		int n = rI();
		long k = rI();
		int[] a = rA(n);
		HashMap<Long, Integer> suffIx = new HashMap<Long, Integer>();
		ArrayList<Long> kPow = new ArrayList<Long>();
		long flag = 1;
		if (k == 1 || k == -1) {
			kPow.add(k);
		} else {
			while (flag <= (long) 100 * 1000 * 1000 * 1000 * 1000 && flag >= (long) -100 * 1000 * 1000 * 1000 * 1000) {
				flag *= k;
				kPow.add(flag);
			}
		}
		long sum = summ(a);
		long[] preFix = new long[n];
		flag = 0;
		for (int i = 0; i < n; i++) {
			preFix[i] = flag + a[i];
			flag = preFix[i];
		}
		for (int i = 0; i < n; i++) {
			suffIx.put(preFix[i], suffIx.getOrDefault(preFix[i], 0) + 1);
		}
		long ans = 0;
		for (long i : kPow) {
			ans += suffIx.getOrDefault(i, 0);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < kPow.size(); j++) {
				long d = kPow.get(j);
				long def = preFix[i] + d;
				ans += suffIx.getOrDefault(def, 0);

			}
			if (suffIx.get(preFix[i]) != null) {
				if (suffIx.get(preFix[i]) == 1) {
					suffIx.remove(preFix[i]);
				} else {
					suffIx.put(preFix[i], suffIx.get(preFix[i]) - 1);
				}
			}
		}
		out.println(ans);

	}

	// ===========================================================================
	long summ(int[] a) {
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans += a[i];
		}
		return ans;
	}

	long summToIndex(int[] a, int index) {
		long ans = 0;
		for (int i = 0; i < index; i++) {
			ans += a[i];
		}
		return ans;
	}

	int minInt(int... values) {
		int min = Integer.MAX_VALUE;
		for (int value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	int maxInt(int... values) {
		int max = Integer.MIN_VALUE;
		for (int value : values) {
			max = Math.max(max, value);
		}
		return max;
	}

	long minLong(long... values) {
		long min = Long.MAX_VALUE;
		for (long value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	long maxLong(long... values) {
		long min = Long.MIN_VALUE;
		for (long value : values) {
			min = Math.max(min, value);
		}
		return min;
	}

	// ==============================================================================

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	long maxA(int[] each) {
		long max = Integer.MIN_VALUE;
		for (int i = 0; i < each.length; i++) {
			if (each[i] > max) {
				max = each[i];

			}
		}
		return max;
	}

	long minA(long[] a) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	// ======================================================
	void solve() throws IOException {
		int n = rI();
		long k = rI();
		int[] a = rA(n);
		HashMap<Long, Integer> suffIx = new HashMap<Long, Integer>();
		ArrayList<Long> kPow = new ArrayList<Long>();
		long flag = 1;
		while (flag <= (long) 100 && flag >= (long) -100) {
			flag *= k;
			kPow.add(flag);
		}
		long sum = summ(a);
		long[] preFix = new long[n];
		flag = 0;
		for (int i = 0; i < n; i++) {
			preFix[i] = flag + a[i];
			flag = preFix[i];
		}
		for (int i = 0; i < n; i++) {
			suffIx.put(preFix[i], suffIx.getOrDefault(preFix[i], 0) + 1);
		}
		long ans = 0;
		for (long i : kPow) {
			ans += suffIx.getOrDefault(i, 0);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < kPow.size(); j++) {
				long d = kPow.get(j);
				long def = preFix[i] + d;
				ans += suffIx.getOrDefault(def, 0);

			}
			if (suffIx.get(preFix[i]) != null) {
				if (suffIx.get(preFix[i]) == 1) {
					suffIx.remove(preFix[i]);
				} else {
					suffIx.put(preFix[i], suffIx.get(preFix[i]) - 1);
				}
			}
		}
		out.println(ans);

	}

	// ===========================================================================
	long summ(int[] a) {
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans += a[i];
		}
		return ans;
	}

	long summToIndex(int[] a, int index) {
		long ans = 0;
		for (int i = 0; i < index; i++) {
			ans += a[i];
		}
		return ans;
	}

	int minInt(int... values) {
		int min = Integer.MAX_VALUE;
		for (int value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	int maxInt(int... values) {
		int max = Integer.MIN_VALUE;
		for (int value : values) {
			max = Math.max(max, value);
		}
		return max;
	}

	long minLong(long... values) {
		long min = Long.MAX_VALUE;
		for (long value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	long maxLong(long... values) {
		long min = Long.MIN_VALUE;
		for (long value : values) {
			min = Math.max(min, value);
		}
		return min;
	}

	// ==============================================================================

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	long maxA(int[] each) {
		long max = Integer.MIN_VALUE;
		for (int i = 0; i < each.length; i++) {
			if (each[i] > max) {
				max = each[i];

			}
		}
		return max;
	}

	long minA(long[] a) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

}


import java.io.*;
import java.util.*;

public class Main {
	static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	boolean checkIndex(int index, int size) {
		return (0 <= index && index < size);
	}

	// ======================================================
	void solve() throws IOException {
		int n = rI();
		long k = rI();
		int[] a = rA(n);
		HashMap<Long, Integer> suffIx = new HashMap<Long, Integer>();
		ArrayList<Long> kPow = new ArrayList<Long>();
		long flag = 1;
		while (flag <= (long) 100 * 1000 * 1000 * 1000 * 1000 && flag >= (long) -100 * 1000 * 1000 * 1000 * 1000) {
			flag *= k;
			kPow.add(flag);
		}
		long sum = summ(a);
		long[] preFix = new long[n];
		flag = 0;
		for (int i = 0; i < n; i++) {
			preFix[i] = flag + a[i];
			flag = preFix[i];
		}
		for (int i = 0; i < n; i++) {
			suffIx.put(preFix[i], suffIx.getOrDefault(preFix[i], 0) + 1);
		}
		long ans = 0;
		for (long i : kPow) {
			ans += suffIx.getOrDefault(i, 0);
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < kPow.size(); j++) {
				long d = kPow.get(j);
				long def = preFix[i] + d;
				ans += suffIx.getOrDefault(def, 0);

			}
			if (suffIx.get(preFix[i]) != null) {
				if (suffIx.get(preFix[i]) == 1) {
					suffIx.remove(preFix[i]);
				} else {
					suffIx.put(preFix[i], suffIx.get(preFix[i]) - 1);
				}
			}
		}
		out.println(ans);

	}

	// ===========================================================================
	long summ(int[] a) {
		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			ans += a[i];
		}
		return ans;
	}

	long summToIndex(int[] a, int index) {
		long ans = 0;
		for (int i = 0; i < index; i++) {
			ans += a[i];
		}
		return ans;
	}

	int minInt(int... values) {
		int min = Integer.MAX_VALUE;
		for (int value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	int maxInt(int... values) {
		int max = Integer.MIN_VALUE;
		for (int value : values) {
			max = Math.max(max, value);
		}
		return max;
	}

	long minLong(long... values) {
		long min = Long.MAX_VALUE;
		for (long value : values) {
			min = Math.min(min, value);
		}
		return min;
	}

	long maxLong(long... values) {
		long min = Long.MIN_VALUE;
		for (long value : values) {
			min = Math.max(min, value);
		}
		return min;
	}

	// ==============================================================================

	public static void main(String[] args) {
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	long maxA(int[] each) {
		long max = Integer.MIN_VALUE;
		for (int i = 0; i < each.length; i++) {
			if (each[i] > max) {
				max = each[i];

			}
		}
		return max;
	}

	long minA(long[] a) {
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.length; i++) {
			if (a[i] < min) {
				min = a[i];
			}
		}
		return min;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}

		tok = new StringTokenizer("");
	}

	void run() {
		try {
			long timeStart = System.currentTimeMillis();

			init();
			solve();

			out.close();

			long timeEnd = System.currentTimeMillis();
			System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
	}

	String readLine() throws IOException {
		return in.readLine();
	}

	String delimiter = " ";

	String rS() throws IOException {
		while (!tok.hasMoreTokens()) {
			String nextLine = readLine();
			if (null == nextLine)
				return null;

			tok = new StringTokenizer(nextLine);
		}

		return tok.nextToken(delimiter);
	}

	int[] rA(int b) {
		int a[] = new int[b];
		for (int i = 0; i < b; i++) {
			try {
				a[i] = rI();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return a;
	}

	int rI() throws IOException {
		return Integer.parseInt(rS());
	}

	long rL() throws IOException {
		return Long.parseLong(rS());
	}

	void sort(int[] a) {
		Integer arr[] = new Integer[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i];
		}
		Arrays.sort(arr);
		for (int i = 0; i < a.length; i++) {
			a[i] = arr[i];
		}
	}

}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class TestClass {

    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String args[] ) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s[] = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        long k = Long.parseLong(s[1]);
        String s1[] = in.readLine().split(" ");
        long a[] = new long[n+1];
        long pre[] = new long[n+1];
        HashMap<Long,Integer> h = new HashMap<Long,Integer>();

        for(int i=1;i<=n;i++)
        {
        	a[i] = Long.parseLong(s1[i-1]);
        	pre[i] = pre[i-1]+a[i];
        }
        long ans=0;
        if(k==1)
        {
        	for(int i=n;i>=0;i--)
        	{
        		if(h.containsKey(pre[i]+1))
        		{
        			ans += h.get(pre[i]+1);
        		}
        		if(h.containsKey(pre[i]))
        		{
        			int x = h.get(pre[i]);
        			h.remove(pre[i]);
        			h.put(pre[i], x+1);
          		}
        		else
        		{
        			h.put(pre[i], 1);
        		}
        	}
        }
        else if(k==-1)
        {
        	for(int i=n;i>=0;i--)
        	{
        		if(h.containsKey(pre[i]+1))
        		{
        			ans += h.get(pre[i]+1);
        		}
        		if(h.containsKey(pre[i]-1))
        		{
        			ans += h.get(pre[i]-1);
        		}
        		if(h.containsKey(pre[i]))
        		{
        			int x = h.get(pre[i]);
        			h.remove(pre[i]);
        			h.put(pre[i], x+1);
          		}
        		else
        		{
        			h.put(pre[i], 1);
        		}
        	}
        }
        else
        {
	        for(int i=n;i>=0;i--)
	        {
	            long p = 1;
	            int j=0;
	        	while(j<51)
	        	{
	        		long x = pre[i]+p;
	        		p = p*k;

	        		if(h.containsKey(x))
	        		{
	        			//System.out.println(pre[i]);
	        			ans += h.get(x);
	        		}
	        		j++;
	        	}
	        	if(h.containsKey(pre[i]))
	    		{
	    			int x = h.get(pre[i]);
	    			h.remove(pre[i]);
	    			h.put(pre[i], x+1);
	    		}
	    		else
	    		{
	    			h.put(pre[i], 1);
	    		}
	        }
        }
        out.println(ans);
        out.close();
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class TestClass {

    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String args[] ) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s[] = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        long k = Long.parseLong(s[1]);
        String s1[] = in.readLine().split(" ");
        long a[] = new long[n+1];
        long pre[] = new long[n+1];
        HashMap<Long,Integer> h = new HashMap<Long,Integer>();

        for(int i=1;i<=n;i++)
        {
        	a[i] = Long.parseLong(s1[i-1]);
        	pre[i] = pre[i-1]+a[i];
        }
        int ans=0;
        for(int i=n;i>=0;i--)
        {
            long p = 1;
            int j=0;
        	while(j<51)
        	{
        		long x = pre[i]+p;
        		p = p*k;

        		if(h.containsKey(x))
        		{
        			//System.out.println(pre[i]);
        			ans += h.get(x);
        		}
        		j++;
        	}
        	if(h.containsKey(pre[i]))
    		{
    			int x = h.get(pre[i]);
    			h.remove(pre[i]);
    			h.put(pre[i], x+1);
    		}
    		else
    		{
    			h.put(pre[i], 1);
    		}
        }
        out.println(ans);
        out.close();
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class TestClass {

    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String args[] ) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s[] = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        long k = Long.parseLong(s[1]);
        String s1[] = in.readLine().split(" ");
        long a[] = new long[n+1];
        long pre[] = new long[n+1];
        HashMap<Long,Integer> h = new HashMap<Long,Integer>();

        for(int i=1;i<=n;i++)
        {
        	a[i] = Long.parseLong(s1[i-1]);
        	pre[i] = pre[i-1]+a[i];
        }
        long ans=0;
        if(k==1)
        {
        	for(int i=n;i>=0;i--)
        	{
        		if(h.containsKey(pre[i]+1))
        		{
        			ans += h.get(pre[i]+1);
        		}
        		if(h.containsKey(pre[i]))
        		{
        			int x = h.get(pre[i]);
        			h.remove(pre[i]);
        			h.put(pre[i], x+1);
          		}
        		else
        		{
        			h.put(pre[i], 1);
        		}
        	}
        }
        if(k==-1)
        {
        	for(int i=n;i>=0;i--)
        	{
        		if(h.containsKey(pre[i]+1))
        		{
        			ans += h.get(pre[i]+1);
        		}
        		if(h.containsKey(pre[i]-1))
        		{
        			ans += h.get(pre[i]-1);
        		}
        		if(h.containsKey(pre[i]))
        		{
        			int x = h.get(pre[i]);
        			h.remove(pre[i]);
        			h.put(pre[i], x+1);
          		}
        		else
        		{
        			h.put(pre[i], 1);
        		}
        	}
        }
        else
        {
	        for(int i=n;i>=0;i--)
	        {
	            long p = 1;
	            int j=0;
	        	while(j<51)
	        	{
	        		long x = pre[i]+p;
	        		p = p*k;

	        		if(h.containsKey(x))
	        		{
	        			//System.out.println(pre[i]);
	        			ans += h.get(x);
	        		}
	        		j++;
	        	}
	        	if(h.containsKey(pre[i]))
	    		{
	    			int x = h.get(pre[i]);
	    			h.remove(pre[i]);
	    			h.put(pre[i], x+1);
	    		}
	    		else
	    		{
	    			h.put(pre[i], 1);
	    		}
	        }
        }
        out.println(ans);
        out.close();
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class TestClass {

    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String args[] ) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s[] = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        long k = Long.parseLong(s[1]);
        String s1[] = in.readLine().split(" ");
        long a[] = new long[n+1];
        long pre[] = new long[n+1];
        HashMap<Long,Integer> h = new HashMap<Long,Integer>();

        for(int i=1;i<=n;i++)
        {
        	a[i] = Long.parseLong(s1[i-1]);
        	pre[i] = pre[i-1]+a[i];
        }
        long ans=0;
        for(int i=n;i>=0;i--)
        {
            long p = 1;
            int j=0;
        	while(j<51)
        	{
        		long x = pre[i]+p;
        		p = p*k;

        		if(h.containsKey(x))
        		{
        			//System.out.println(pre[i]);
        			ans += h.get(x);
        		}
        		j++;
        	}
        	if(h.containsKey(pre[i]))
    		{
    			int x = h.get(pre[i]);
    			h.remove(pre[i]);
    			h.put(pre[i], x+1);
    		}
    		else
    		{
    			h.put(pre[i], 1);
    		}
        }
        out.println(ans);
        out.close();
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class TestClass {

    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String args[] ) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s[] = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        long k = Long.parseLong(s[1]);
        String s1[] = in.readLine().split(" ");
        long a[] = new long[n+1];
        long pre[] = new long[n+1];
        HashMap<Long,Integer> h = new HashMap<Long,Integer>();

        for(int i=1;i<=n;i++)
        {
        	a[i] = Long.parseLong(s1[i-1]);
        	pre[i] = pre[i-1]+a[i];
        }
        long ans=0;
        if(k==1)
        {
        	for(int i=n;i>=0;i--)
        	{
        		if(h.containsKey(pre[i]+1))
        		{
        			ans += h.get(pre[i]+1);
        		}
        		if(h.containsKey(pre[i]))
        		{
        			int x = h.get(pre[i]);
        			h.remove(pre[i]);
        			h.put(pre[i], x+1);
          		}
        		else
        		{
        			h.put(pre[i], 1);
        		}
        	}
        }
        else if(k==-1)
        {
        	for(int i=n;i>=0;i--)
        	{
        		if(h.containsKey(pre[i]+1))
        		{
        			ans += h.get(pre[i]+1);
        		}
        		if(h.containsKey(pre[i]-1))
        		{
        			ans += h.get(pre[i]-1);
        		}
        		if(h.containsKey(pre[i]))
        		{
        			int x = h.get(pre[i]);
        			h.remove(pre[i]);
        			h.put(pre[i], x+1);
          		}
        		else
        		{
        			h.put(pre[i], 1);
        		}
        	}
        }
        else
        {
	        for(int i=n;i>=0;i--)
	        {
	            long p = 1;
	            int j=0;
	        	while(j<51)
	        	{
	        		long x = pre[i]+p;
	        		p = p*k;

	        		if(h.containsKey(x))
	        		{
	        			//System.out.println(pre[i]);
	        			ans += h.get(x);
	        		}
	        		j++;
	        		if(Math.abs(p)>1e15)
	        			break;
	        	}
	        	//System.out.println(p);
	        	if(h.containsKey(pre[i]))
	    		{
	    			int x = h.get(pre[i]);
	    			h.remove(pre[i]);
	    			h.put(pre[i], x+1);
	    		}
	    		else
	    		{
	    			h.put(pre[i], 1);
	    		}
	        }
        }
        out.println(ans);
        out.close();
    }
}


import java.io.*;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
    private boolean isLocalJudgment = false;
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = in.nextInts(n);
        int answer = 0;
        if (k == 1) {
            for (int i : a) {
                if (i == 1) {
                    answer++;
                }
            }
        } else {
            Map<Long, Integer> cnt = new TreeMap<>();
            cnt.put(0L, 1);
            long cur = 0;
            for (int e : a) {
                cur += e;
                long p = 1;
                while (p <= (long) 1e16) {
                    answer += cnt.getOrDefault(cur - p, 0);
                    p *= k;
                }
                cnt.put(cur, 1 + cnt.getOrDefault(cur, 0));
            }
        }
        out.println(answer);
    }

    private void print(Set<String> toKill) {
        for (String s : toKill) {
            out.print(s);
            out.print(' ');
        }
        out.println();
    }

    private void run() throws IOException {
        if (isLocalJudgment) {
            in = new FastScanner("input.txt");
            out = new PrintWriter(new File("output.txt"));
            while (in.hasNext()) {
                solve();
                out.flush();
            }
        } else {
            in = new FastScanner();
            out = new PrintWriter(System.out, false);
            solve();
        }
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public FastScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public FastScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken();
    }

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }

    public double[][] next2Doubles(int n, int m) throws IOException {
        double[][] arr = new double[n][];
        for (int i = 0; i < n; i++) {
            arr[i] = nextDoubles(m);
        }
        return arr;
    }
}


import java.io.*;
import java.util.*;

public class Main {
    private boolean isLocalJudgment = false;
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = in.nextInts(n);
        long answer = 0;
        Map<Long, Integer> cnt = new HashMap<>();
        cnt.put(0L, 1);
        long cur = 0;
        for (int e : a) {
            cur += e;
            if (k == 1) {
                answer += cnt.getOrDefault(cur - 1, 0);
            } else if (k == -1) {
                answer += cnt.getOrDefault(cur - 1, 0);
                answer += cnt.getOrDefault(cur + 1, 0);
            } else {
                long p = 1;
                while (Math.abs(p) <= (long) 1e16) {
                    answer += cnt.getOrDefault(cur - p, 0);
                    p *= k;
                }
            }
            cnt.put(cur, 1 + cnt.getOrDefault(cur, 0));
        }
        out.println(answer);
    }

    private void print(Set<String> toKill) {
        for (String s : toKill) {
            out.print(s);
            out.print(' ');
        }
        out.println();
    }

    private void run() throws IOException {
        if (isLocalJudgment) {
            in = new FastScanner("input.txt");
            out = new PrintWriter(new File("output.txt"));
            while (in.hasNext()) {
                solve();
                out.flush();
            }
        } else {
            in = new FastScanner();
            out = new PrintWriter(System.out, false);
            solve();
        }
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public FastScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public FastScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken();
    }

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }

    public double[][] next2Doubles(int n, int m) throws IOException {
        double[][] arr = new double[n][];
        for (int i = 0; i < n; i++) {
            arr[i] = nextDoubles(m);
        }
        return arr;
    }
}