import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_400 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int k = in.nextInt();
        ArrayList<Long> list = new ArrayList();
        long s = 1;
        list.add(1L);
        while (s <= 1e15) {
            s *= k;
            list.add(s);
        }
        HashMap<Long, Integer> map = new HashMap();
        long total = 0;
        map.put(0L, 1);
        long result = 0;
        for (int i = 0; i < n; i++) {
            total += in.nextLong();
            for (long v : list) {
                long need = total - v;
                result += map.getOrDefault(need, 0);
            }
            map.put(total, map.getOrDefault(total, 0) + 1);
        }
        out.println(result);
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.util.*;
import java.io.*;
public class MollysChemicals {

    /************************ SOLUTION STARTS HERE ************************/

    private static void solve() {

        long MAX = (long) 1e14;
        ArrayList<Long> possiblePow = new ArrayList<>();

        int N = nextInt();
        long K = nextLong();
        long arr[] = nextLongArray(N);

        long pow = 1;
        while(pow <= MAX) {
            possiblePow.add(pow);
            pow *= K;
        }

        HashMap<Long , Integer> freq = new HashMap<>();
        freq.put(0L, 1);
        long cnt = 0;
        long prefixSum = 0;

        for(long a : arr) {
            prefixSum += a;
            for(long KPow : possiblePow)
                cnt += freq.getOrDefault(prefixSum - KPow, 0);
            freq.put(prefixSum, freq.getOrDefault(prefixSum, 0) + 1);
        }

        println(cnt);
    }

    /************************ SOLUTION ENDS HERE ************************/

    /************************ TEMPLATE STARTS HERE **********************/

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        st     = null;
        solve();
        reader.close();
        writer.close();
    }

    static BufferedReader reader;
    static PrintWriter    writer;
    static StringTokenizer st;

    static String next()
    {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
    st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
    static String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
    static int    nextInt()   {return Integer.parseInt(next());}
    static long   nextLong()  {return Long.parseLong(next());}
    static double nextDouble(){return Double.parseDouble(next());}
    static char   nextChar()  {return next().charAt(0);}
    static int[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}
    static long[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}
    static int[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}
    static long[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}
    static void   print(Object o)  { writer.print(o);  }
    static void   println(Object o){ writer.println(o);}

    /************************ TEMPLATE ENDS HERE ************************/

}


import java.util.*;
import java.io.*;
public class MollysChemicals {

    /************************ SOLUTION STARTS HERE ************************/

    private static void solve() {

        long MAX = (long) 1e14;
        ArrayList<Long> possiblePow = new ArrayList<>();

        int N = nextInt();
        long K = nextLong();
        long arr[] = nextLongArray(N);

        long pow = 1;
        while(pow <= MAX) {
            possiblePow.add(pow);
            pow *= K;
            if(K == 1) break;
        }

        TreeMap<Long , Integer> freq = new TreeMap<>();
        freq.put(0L, 1);
        long cnt = 0;
        long prefixSum = 0;

        for(long a : arr) {
            prefixSum += a;

            for(long KPow : possiblePow)
                cnt += freq.getOrDefault(prefixSum - KPow, 0);

            freq.put(prefixSum, freq.getOrDefault(prefixSum, 0) + 1);
        }

        println(cnt);
    }

    /************************ SOLUTION ENDS HERE ************************/

    /************************ TEMPLATE STARTS HERE **********************/

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        st     = null;
        solve();
        reader.close();
        writer.close();
    }

    static BufferedReader reader;
    static PrintWriter    writer;
    static StringTokenizer st;

    static String next()
    {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
    st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
    static String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
    static int    nextInt()   {return Integer.parseInt(next());}
    static long   nextLong()  {return Long.parseLong(next());}
    static double nextDouble(){return Double.parseDouble(next());}
    static char   nextChar()  {return next().charAt(0);}
    static int[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}
    static long[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}
    static int[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}
    static long[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}
    static void   print(Object o)  { writer.print(o);  }
    static void   println(Object o){ writer.println(o);}

    /************************ TEMPLATE ENDS HERE ************************/

}


import java.util.*;
import java.io.*;
public class MollysChemicals {

    /************************ SOLUTION STARTS HERE ************************/

    private static void solve() {

        long MAX = (long) 1e14;
        ArrayList<Long> possiblePow = new ArrayList<>();

        int N = nextInt();
        long K = nextLong();
        long arr[] = nextLongArray(N);

        possiblePow.add(1L);
        long pow = K;

        while(Math.abs(pow) <= MAX) {
            if(pow == 1) break;
            possiblePow.add(pow);
            pow *= K;
        }

        HashMap<Long , Integer> freq = new HashMap<>();
        freq.put(0L, 1);
        long cnt = 0;
        long prefixSum = 0;

        for(long a : arr) {
            prefixSum += a;

            for(long KPow : possiblePow)
                cnt += freq.getOrDefault(prefixSum - KPow, 0);

            freq.put(prefixSum, freq.getOrDefault(prefixSum, 0) + 1);
        }

        println(cnt);
    }

    /************************ SOLUTION ENDS HERE ************************/

    /************************ TEMPLATE STARTS HERE **********************/

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        st     = null;
        solve();
        reader.close();
        writer.close();
    }

    static BufferedReader reader;
    static PrintWriter    writer;
    static StringTokenizer st;

    static String next()
    {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
    st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
    static String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
    static int    nextInt()   {return Integer.parseInt(next());}
    static long   nextLong()  {return Long.parseLong(next());}
    static double nextDouble(){return Double.parseDouble(next());}
    static char   nextChar()  {return next().charAt(0);}
    static int[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}
    static long[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}
    static int[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}
    static long[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}
    static void   print(Object o)  { writer.print(o);  }
    static void   println(Object o){ writer.println(o);}

    /************************ TEMPLATE ENDS HERE ************************/

}


import java.util.*;
import java.io.*;
public class MollysChemicals {

    /************************ SOLUTION STARTS HERE ************************/

    private static void solve() {

        long MAX = (long) 1e14;
        ArrayList<Long> possiblePow = new ArrayList<>();

        int N = nextInt();
        long K = nextLong();
        long arr[] = nextLongArray(N);

        long pow = 1;
        while(pow <= MAX) {
            possiblePow.add(pow);
            pow *= K;
            if(K == 1) break;
        }

        HashMap<Long , Integer> freq = new HashMap<>();
        freq.put(0L, 1);
        long cnt = 0;
        long prefixSum = 0;

        for(long a : arr) {
            prefixSum += a;
            for(long KPow : possiblePow)
                cnt += freq.getOrDefault(prefixSum - KPow, 0);
            freq.put(prefixSum, freq.getOrDefault(prefixSum, 0) + 1);
        }

        println(cnt);
    }

    /************************ SOLUTION ENDS HERE ************************/

    /************************ TEMPLATE STARTS HERE **********************/

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        st     = null;
        solve();
        reader.close();
        writer.close();
    }

    static BufferedReader reader;
    static PrintWriter    writer;
    static StringTokenizer st;

    static String next()
    {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
    st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
    static String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
    static int    nextInt()   {return Integer.parseInt(next());}
    static long   nextLong()  {return Long.parseLong(next());}
    static double nextDouble(){return Double.parseDouble(next());}
    static char   nextChar()  {return next().charAt(0);}
    static int[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}
    static long[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}
    static int[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}
    static long[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}
    static void   print(Object o)  { writer.print(o);  }
    static void   println(Object o){ writer.println(o);}

    /************************ TEMPLATE ENDS HERE ************************/

}


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

public class Abc {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),k=sc.nextInt();
        int arr[]=new int[n];
        long sum=0;
        long max=0;
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            sum+=arr[i];
            max=Math.max(max,Math.abs(sum));
        }
        long pow[]=new long[60];
        if (k==1)pow[0]=k;
        else {
            pow[0]=1;
            for (int i=1;i<60;i++){
                pow[i]=pow[i-1]*k;
                if (pow[i]>=max)break;
            }
        }
        int c=0;
        for (int i=0;i<60;i++) {
            if (pow[i] == 0) break;
            Map<Long,Integer> map=new HashMap<>();
            sum=0;
            for (int j=0;j<n;j++){
                sum+=arr[j];
                if (sum==pow[i])c++;
                else c+=map.getOrDefault(sum-pow[i],0);
                map.put(sum,map.getOrDefault(sum,0)+1);
            }
        }
        System.out.println(c);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class Abc {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),k=sc.nextInt();
        int arr[]=new int[n];
        long sum=0;
        long max=0;
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            sum+=arr[i];
            max=Math.max(max,Math.abs(sum));
        }
        long pow[]=new long[60];
        if (k==1)pow[0]=k;
        else {
            pow[0]=1;
            for (int i=1;i<60;i++){
                pow[i]=pow[i-1]*k;
                if (pow[i]>=max)break;
            }
        }
        long c=0;
        for (int i=0;i<60;i++) {
            if (pow[i] == 0) break;
            Map<Long,Integer> map=new HashMap<>();
            sum=0;
            for (int j=0;j<n;j++){
                sum+=arr[j];
                if (sum==pow[i])c++;
                else c+=map.getOrDefault(sum-pow[i],0);
                map.put(sum,map.getOrDefault(sum,0)+1);
            }
        }
        System.out.println(c);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class Abc {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),k=sc.nextInt();
        int arr[]=new int[n];
        long sum=0;
        long max=0;
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            sum+=arr[i];
            max=Math.max(max,Math.abs(sum));
        }
        long pow[]=new long[60];
        if (k==1)pow[0]=k;
        else {
            pow[0]=1;
            for (int i=1;i<60;i++){
                pow[i]=pow[i-1]*k;
                if (pow[i]>=max)break;
            }
        }
        long c=0;
        for (int i=0;i<60;i++) {
            if (pow[i] == 0) break;
            HashMap <Long, Integer> prevSum = new HashMap<>();
            sum=pow[i];

            // Sum of elements so far.
            long currsum = 0;

            for (int j = 0; j < n; j++) {

                // Add current element to sum so far.
                currsum += arr[j];

                // If currsum is equal to desired sum,
                // then a new subarray is found. So
                // increase count of subarrays.
                if (currsum == sum)
                    c++;

                // currsum exceeds given sum by currsum
                //  - sum. Find number of subarrays having
                // this sum and exclude those subarrays
                // from currsum by increasing count by
                // same amount.
                if (prevSum.containsKey(currsum - sum))
                    c += prevSum.get(currsum - sum);

                // Add currsum value to count of
                // different values of sum.
                Integer count = prevSum.get(currsum);
                if (count == null)
                    prevSum.put(currsum, 1);
                else
                    prevSum.put(currsum, count+1);
            }
        }
        System.out.println(c);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class Abc {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),k=sc.nextInt();
        int arr[]=new int[n];
        long sum=0;
        long max=0;
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            sum+=arr[i];
            max=Math.max(max,Math.abs(sum));
        }
        long pow[]=new long[60];
        if (k==1)pow[0]=1;
        else if (k==-1){
            pow[0]=1;pow[1]=-1;
        }
        else {
            pow[0]=1;
            for (int i=1;i<60;i++){
                pow[i]=pow[i-1]*k;
                if (pow[i]>=max)break;
            }
        }
        long c=0;
        for (int i=0;i<60;i++) {
            if (pow[i] == 0) break;
            Map<Long,Integer> map=new HashMap<>();
            sum=0;
            for (int j=0;j<n;j++){
                sum+=arr[j];
                if (sum==pow[i])c++;
                c+=map.getOrDefault(sum-pow[i],0);
                map.put(sum,map.getOrDefault(sum,0)+1);
            }
        }
        System.out.println(c);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class Abc {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),k=sc.nextInt();
        int arr[]=new int[n];
        long sum=0;
        long max=0;
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            sum+=arr[i];
            max=Math.max(max,Math.abs(sum));
        }
        long pow[]=new long[60];
        if (k==1)pow[0]=k;
        else {
            pow[0]=1;
            for (int i=1;i<60;i++){
                pow[i]=pow[i-1]*k;
                if (pow[i]>=max)break;
            }
        }
        long c=0;
        for (int i=0;i<60;i++) {
            if (pow[i] == 0) break;
            Map<Long,Integer> map=new HashMap<>();
            sum=0;
            for (int j=0;j<n;j++){
                sum+=arr[j];
                if (sum==pow[i])c++;
                c+=map.getOrDefault(sum-pow[i],0);
                map.put(sum,map.getOrDefault(sum,0)+1);
            }
        }
        System.out.println(c);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class Abc {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),k=sc.nextInt();
        int arr[]=new int[n];
        long sum=0;
        long max=0;
        for (int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            sum+=arr[i];
            max=Math.max(max,Math.abs(sum));
        }
        long pow[]=new long[60];
        if (k==1)pow[0]=k;
        else {
            pow[0]=1;
            for (int i=1;i<60;i++){
                pow[i]=pow[i-1]*k;
                if (pow[i]>=max)break;
            }
        }
        long c=0;
        for (int i=0;i<60;i++) {
            if (pow[i] == 0) break;
            HashMap <Long, Integer> prevSum = new HashMap<>();

            // Sum of elements so far.
            long currsum = 0;

            for (int j = 0; j < n; j++) {

                // Add current element to sum so far.
                currsum += arr[j];

                // If currsum is equal to desired sum,
                // then a new subarray is found. So
                // increase count of subarrays.
                if (currsum == sum)
                    c++;

                // currsum exceeds given sum by currsum
                //  - sum. Find number of subarrays having
                // this sum and exclude those subarrays
                // from currsum by increasing count by
                // same amount.
                if (prevSum.containsKey(currsum - sum))
                    c += prevSum.get(currsum - sum);

                // Add currsum value to count of
                // different values of sum.
                Integer count = prevSum.get(currsum);
                if (count == null)
                    prevSum.put(currsum, 1);
                else
                    prevSum.put(currsum, count+1);
            }
        }
        System.out.println(c);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long maxSum = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                maxSum += array[i];
            }
        }
        map.put(0L, 1L);
        long highestPower = (long) (Math.log(maxSum) / Math.log(Math.abs(k))) + 1;
        if (k == -1) {
            highestPower = 1L;
        }
        if (k == 1) {
            highestPower = 0L;
        }
        for (int j = 0; j < prefix.length; j++) {
            for (int i = 0; i <= highestPower; i++) {
                long currentValue = (long) Math.pow(k, i);
                long remain = prefix[j] - currentValue;
                if (map.containsKey(remain)) {
                    answer += map.get(remain);
                }
            }
            map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long maxSum = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                maxSum += array[i];
            }
        }
        map.put(0L, 1L);
        long highestPower = (long) (Math.log(maxSum) / Math.log(Math.abs(k))) + 1;
        for (int j = 0; j < prefix.length; j++) {
            for (int i = 0; i <= highestPower; i++) {
                long currentValue = (long) Math.pow(k, i);
                long remain = prefix[j] - currentValue;
                if (map.containsKey(remain)) {
                    answer += map.get(remain);
                }
            }
            map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long upperBound = (long)(Math.pow(10, 14));
        HashMap<Long, Long> map = new HashMap<>();
        map.put(0L, 1L);
        for (int i = 0; i < prefix.length; i++) {
            for (long j = 1; j <= upperBound; j *= k) {
                long remainValue = prefix[i] - j;
                if (map.containsKey(remainValue)) {
                    answer += map.get(remainValue);
                }
                if (k == 1) {
                    break;
                }
                if (k == -1) {
                    break;
                }
            }
            map.put(prefix[i], map.containsKey(prefix[i]) ? map.get(prefix[i]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long maxSum = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                maxSum += array[i];
            }
        }
        map.put(0L, 1L);
        long highestPower = (long) (Math.log(maxSum) / Math.log(Math.abs(k))) + 1;
        if (k == -1) {
            highestPower = 2L;
        }
        for (int j = 0; j < prefix.length; j++) {
            for (int i = 0; i <= highestPower; i++) {
                long currentValue = (long) Math.pow(k, i);
                long remain = prefix[j] - currentValue;
                if (map.containsKey(remain)) {
                    answer += map.get(remain);
                }
            }
            map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        map.put(0L, 1L);
        long highestPower = 1000000;
        if (k == -1) {
            highestPower = 1L;
        }
        if (k == 1) {
            highestPower = 0L;
        }
        for (int j = 0; j < prefix.length; j++) {
            for (int i = 0; i <= highestPower; i++) {
                long currentValue = (long) Math.pow(k, i);
                long remain = prefix[j] - currentValue;
                if (map.containsKey(remain)) {
                    answer += map.get(remain);
                }
            }
            map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long maxSum = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                maxSum += array[i];
            }
        }
        map.put(0L, 1L);
        long highestPower = (long) (Math.log(maxSum) / Math.log(Math.abs(k))) + 1;
        if (k == -1) {
            highestPower = 1L;
        }
        if (k == 1) {
            highestPower = 0L;
        }
        if (k < -1) {
            highestPower = (long)(Math.log(Math.pow(10, 14)) / Math.log(Math.abs(k))) + 1;
            for (int j = 0; j < prefix.length; j++) {
                for (int i = (int)(-1 * highestPower); i <= highestPower; i++) {
                    if (!(i % 2 == 1 && i < 0)) {
                        long currentValue = (long) Math.pow(k, i);
                        long remain = prefix[j] - currentValue;
                        if (map.containsKey(remain)) {
                            answer += map.get(remain);
                        }
                    }
                }
                map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
            }
        } else {
            for (int j = 0; j < prefix.length; j++) {
                for (int i = 0; i <= highestPower; i++) {
                    long currentValue = (long) Math.pow(k, i);
                    long remain = prefix[j] - currentValue;
                    if (map.containsKey(remain)) {
                        answer += map.get(remain);
                    }
                }
                map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
            }
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long maxSum = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                maxSum += array[i];
            }
        }
        map.put(0L, 1L);
        long highestPower = (long) (Math.log(maxSum) / Math.log(Math.abs(k))) + 1;
        if (k == -1) {
            highestPower = 1L;
        }
        if (k == 1) {
            highestPower = 0L;
        }
        for (int j = 0; j < prefix.length; j++) {
            for (int i = -1 * (int)highestPower; i <= highestPower; i++) {
                long currentValue = (long) Math.pow(k, i);
                long remain = prefix[j] - currentValue;
                if (map.containsKey(remain)) {
                    answer += map.get(remain);
                }
            }
            map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long maxSum = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                maxSum += array[i];
            }
        }
        map.put(0L, 1L);
        long highestPower = (long) (Math.log(maxSum) / Math.log(Math.abs(k))) + 1;
        if (k == -1) {
            highestPower = 1L;
        }
        for (int j = 0; j < prefix.length; j++) {
            for (int i = 0; i <= highestPower; i++) {
                long currentValue = (long) Math.pow(k, i);
                long remain = prefix[j] - currentValue;
                if (map.containsKey(remain)) {
                    answer += map.get(remain);
                }
            }
            map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long upperBound = (long)(Math.pow(10, 14));
        if (k == 1) {
            upperBound = 1;
        }
        if (k == -1) {
            upperBound = 1;
        }
        HashMap<Long, Long> map = new HashMap<>();
        map.put(0L, 1L);
        for (int i = 0; i < prefix.length; i++) {
            for (long j = 1; j <= upperBound; j *= k) {
                long remainValue = prefix[i] - j;
                if (map.containsKey(remainValue)) {
                    answer += map.get(remainValue);
                }
            }
            map.put(prefix[i], map.containsKey(prefix[i]) ? map.get(prefix[i]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        long upperBound = (long)(Math.pow(10, 14));
        HashMap<Long, Long> map = new HashMap<>();
        map.put(0L, 1L);
        if (k == 1 || k == -1) {
            upperBound = 1;
        }
        for (int i = 0; i < prefix.length; i++) {
            int iteration = 0;
            for (long j = 1; j <= upperBound; j *= k) {
                long remainValue = prefix[i] - j;
                if (map.containsKey(remainValue)) {
                    answer += map.get(remainValue);
                }
                iteration++;
                if (k == 1 && iteration == 1) {
                    break;
                }
                if (k == -1 && iteration == 2) {
                    break;
                }
            }
            map.put(prefix[i], map.containsKey(prefix[i]) ? map.get(prefix[i]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/**
 * Created by qicodeng on 2/23/17.
 */

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Codeforces_round_400_div_2_MollysChemicals {
    public static void main(String[] args) {
        FScanner input = new FScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int[] array = new int[input.nextInt()];
        int k = input.nextInt();
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        long[] prefix = new long[array.length];
        prefix[0] = array[0];
        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 1; i < prefix.length; i++) {
            prefix[i] = prefix[i - 1] + array[i];
        }
        long answer = 0;
        map.put(0L, 1L);
        long highestPower = (long)(Math.pow(10, 9) * Math.pow(10, 5));
        if (k == -1) {
            highestPower = 1L;
        }
        if (k == 1) {
            highestPower = 0L;
        }
        for (int j = 0; j < prefix.length; j++) {
            for (int i = 0; i <= highestPower; i++) {
                long currentValue = (long) Math.pow(k, i);
                long remain = prefix[j] - currentValue;
                if (map.containsKey(remain)) {
                    answer += map.get(remain);
                }
            }
            map.put(prefix[j], map.containsKey(prefix[j]) ? map.get(prefix[j]) + 1 : 1);
        }
        out.println(answer);
        out.close();
    }

    public static PrintWriter out;

    public static class FScanner {
        BufferedReader br;
        StringTokenizer st;

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

        private String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException 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 str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class Myclass {
	 public static ArrayList a[]=new ArrayList[3000001];
	 public static long dp[][][]=new long[20][4][2];
	 static Vector<Integer>v=new Vector<>();
	 static void ini() {
		 for(int i=0;i<20;i++) {
			 for(int j=0;j<4;j++) {
				 for(int k=0;k<2;k++)
					 dp[i][j][k]=-1;
			 }
		 }
	 }
	 static long rec(int id,int freq,int st) {
    	 if(id==v.size())
    		 return 1L;
    	 if(freq>3)
    		 return 0;
    	 if(st==1 && dp[id][freq][st]!=-1) {
    		 return dp[id][freq][st];
    	 }
    	 long ans=0L;
    	 if(st==1) {
    		 for(int i=1;i<=9;i++) {
    			 ans+=rec(id+1,freq+1,1);
    		 }
    		 ans+=rec(id+1,freq,1);
    	 }
    	 else
    	 {
    		 for(int i=0;i<v.get(id);i++) {
    			 ans+=rec(id+1,(i!=0)?freq+1:freq,1);
    		 }
    		 ans+=rec(id+1,((v.get(id))!=0)?freq+1:freq,0);
    	 }
    	 dp[id][freq][st]=ans;
    	 return ans;
     }
     public static void main(String[] args)
    {
    	InputReader in=new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        HashMap<Long,Integer>hm=new HashMap<>();
        int n=in.nextInt();
        long k=in.nextLong();
        long a[]=new long[n];
        for(int i=0;i<n;i++) {
        	a[i]=in.nextLong();

        }
        long pre[]=new long[n+1];
        for(int i=1;i<=n;i++)
        	pre[i]=pre[i-1]+a[i-1];
        hm.put(0L, 1);
        int ans=0;
        for(int i=1;i<=n;i++) {
        	long ini=1;
        	while(Math.abs(ini)<10e15) {

        		if(hm.containsKey(pre[i]-ini)) {
        			ans+=hm.get(pre[i]-ini);
        		}
        		ini*=k;
        	}
        	if(hm.containsKey(pre[i]))
        		hm.put(pre[i], hm.get(pre[i])+1);
        	else
        		hm.put(pre[i], 1);

        }
        pw.println(ans);
        pw.flush();
        pw.close();

    }
    private static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
   static class InputReader
        {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
        public int snext()
        {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars)
            {
                curChar = 0;
                try
                {
                    snumChars = stream.read(buf);
                }

                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

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

        public int[] nextIntArray(int n)
        {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = nextInt();
            }
            return a;
        }
        static class tri implements Comparable<tri> {
            int p, c, l;

            tri(int p, int c, int l) {
                this.p = p;
                this.c = c;
                this.l = l;
            }

            public int compareTo(tri o) {
                return Integer.compare(l, o.l);
            }
        }

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

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

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
   public static long modularExponentiation(long x,long n,long M)
   {
       long result=1;
       while(n>0)
       {
           if(n % 2 ==1)
               result=(result%M * x%M)%M;
           x=(x%M * x%M)%M;
           n=n/2;
       }
       return result;
   }
    static class pair implements Comparable<pair>{
    	Integer x;
        Long y;
        pair(Integer x,long  val){
            this.x=x;
            this.y=val;
        }
         public int compareTo(pair o) {
                if(o.x>x) {
                	return -1;
                }
                if(o.x<x) {
                	return 1;
                }
                if(o.y>y) {
                	return -1;
                }
                if(o.x<x) {
                	return 1;
                }
                return 0;

          }
         public String toString(){
            return (x+" "+y);
        }
  }

}


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

public class Myclass {
	 public static ArrayList a[]=new ArrayList[3000001];
	 public static long dp[][][]=new long[20][4][2];
	 static Vector<Integer>v=new Vector<>();
	 static void ini() {
		 for(int i=0;i<20;i++) {
			 for(int j=0;j<4;j++) {
				 for(int k=0;k<2;k++)
					 dp[i][j][k]=-1;
			 }
		 }
	 }
	 static long rec(int id,int freq,int st) {
    	 if(id==v.size())
    		 return 1L;
    	 if(freq>3)
    		 return 0;
    	 if(st==1 && dp[id][freq][st]!=-1) {
    		 return dp[id][freq][st];
    	 }
    	 long ans=0L;
    	 if(st==1) {
    		 for(int i=1;i<=9;i++) {
    			 ans+=rec(id+1,freq+1,1);
    		 }
    		 ans+=rec(id+1,freq,1);
    	 }
    	 else
    	 {
    		 for(int i=0;i<v.get(id);i++) {
    			 ans+=rec(id+1,(i!=0)?freq+1:freq,1);
    		 }
    		 ans+=rec(id+1,((v.get(id))!=0)?freq+1:freq,0);
    	 }
    	 dp[id][freq][st]=ans;
    	 return ans;
     }
     public static void main(String[] args)
    {
    	InputReader in=new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        HashMap<Long,Integer>hm=new HashMap<>();
        int n=in.nextInt();
        long k=in.nextLong();
        long a[]=new long[n];
        for(int i=0;i<n;i++) {
        	a[i]=in.nextLong();

        }
        long pre[]=new long[n+1];
        for(int i=1;i<=n;i++)
        	pre[i]=pre[i-1]+a[i-1];
        hm.put(0L, 1);
        long ans=0;
        for(int i=1;i<=n;i++) {
        	long ini=1;
        	while(Math.abs(ini)<10e15) {

        		if(hm.containsKey(pre[i]-ini)) {
        			ans+=hm.get(pre[i]-ini);
        		}
        		ini*=k;
        	}
        	if(hm.containsKey(pre[i]))
        		hm.put(pre[i], hm.get(pre[i])+1);
        	else
        		hm.put(pre[i], 1);

        }
        pw.println(ans);
        pw.flush();
        pw.close();

    }
    private static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
   static class InputReader
        {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
        public int snext()
        {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars)
            {
                curChar = 0;
                try
                {
                    snumChars = stream.read(buf);
                }

                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

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

        public int[] nextIntArray(int n)
        {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = nextInt();
            }
            return a;
        }
        static class tri implements Comparable<tri> {
            int p, c, l;

            tri(int p, int c, int l) {
                this.p = p;
                this.c = c;
                this.l = l;
            }

            public int compareTo(tri o) {
                return Integer.compare(l, o.l);
            }
        }

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

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

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
   public static long modularExponentiation(long x,long n,long M)
   {
       long result=1;
       while(n>0)
       {
           if(n % 2 ==1)
               result=(result%M * x%M)%M;
           x=(x%M * x%M)%M;
           n=n/2;
       }
       return result;
   }
    static class pair implements Comparable<pair>{
    	Integer x;
        Long y;
        pair(Integer x,long  val){
            this.x=x;
            this.y=val;
        }
         public int compareTo(pair o) {
                if(o.x>x) {
                	return -1;
                }
                if(o.x<x) {
                	return 1;
                }
                if(o.y>y) {
                	return -1;
                }
                if(o.x<x) {
                	return 1;
                }
                return 0;

          }
         public String toString(){
            return (x+" "+y);
        }
  }

}


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

public class Myclass {
	 public static ArrayList a[]=new ArrayList[3000001];
	 public static long dp[][][]=new long[20][4][2];
	 static Vector<Integer>v=new Vector<>();
	 static void ini() {
		 for(int i=0;i<20;i++) {
			 for(int j=0;j<4;j++) {
				 for(int k=0;k<2;k++)
					 dp[i][j][k]=-1;
			 }
		 }
	 }
	 static long rec(int id,int freq,int st) {
    	 if(id==v.size())
    		 return 1L;
    	 if(freq>3)
    		 return 0;
    	 if(st==1 && dp[id][freq][st]!=-1) {
    		 return dp[id][freq][st];
    	 }
    	 long ans=0L;
    	 if(st==1) {
    		 for(int i=1;i<=9;i++) {
    			 ans+=rec(id+1,freq+1,1);
    		 }
    		 ans+=rec(id+1,freq,1);
    	 }
    	 else
    	 {
    		 for(int i=0;i<v.get(id);i++) {
    			 ans+=rec(id+1,(i!=0)?freq+1:freq,1);
    		 }
    		 ans+=rec(id+1,((v.get(id))!=0)?freq+1:freq,0);
    	 }
    	 dp[id][freq][st]=ans;
    	 return ans;
     }
     public static void main(String[] args)
    {
    	InputReader in=new InputReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        HashMap<Long,Integer>hm=new HashMap<>();
        int n=in.nextInt();
        long k=in.nextLong();
        long a[]=new long[n];
        for(int i=0;i<n;i++) {
        	a[i]=in.nextLong();

        }
        long pre[]=new long[n+1];
        for(int i=1;i<=n;i++)
        	pre[i]=pre[i-1]+a[i-1];
        hm.put(0L, 1);
        long ans=0;
        for(int i=1;i<=n;i++) {
        	long ini=1;
        	int cnt=0;
        	while(Math.abs(ini)<10e15) {
            	cnt++;
        		if(hm.containsKey(pre[i]-ini)) {
        			ans+=hm.get(pre[i]-ini);
        		}
        		ini*=k;
        		if(k==1 && cnt==1)
        			break;
        		if(k==-1 && cnt==2)
        			break;
        	}
        	if(hm.containsKey(pre[i]))
        		hm.put(pre[i], hm.get(pre[i])+1);
        	else
        		hm.put(pre[i], 1);

        }
        pw.println(ans);
        pw.flush();
        pw.close();

    }
    private static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
   static class InputReader
        {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
        public int snext()
        {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars)
            {
                curChar = 0;
                try
                {
                    snumChars = stream.read(buf);
                }

                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

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

        public int[] nextIntArray(int n)
        {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = nextInt();
            }
            return a;
        }
        static class tri implements Comparable<tri> {
            int p, c, l;

            tri(int p, int c, int l) {
                this.p = p;
                this.c = c;
                this.l = l;
            }

            public int compareTo(tri o) {
                return Integer.compare(l, o.l);
            }
        }

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

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

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
   public static long modularExponentiation(long x,long n,long M)
   {
       long result=1;
       while(n>0)
       {
           if(n % 2 ==1)
               result=(result%M * x%M)%M;
           x=(x%M * x%M)%M;
           n=n/2;
       }
       return result;
   }
    static class pair implements Comparable<pair>{
    	Integer x;
        Long y;
        pair(Integer x,long  val){
            this.x=x;
            this.y=val;
        }
         public int compareTo(pair o) {
                if(o.x>x) {
                	return -1;
                }
                if(o.x<x) {
                	return 1;
                }
                if(o.y>y) {
                	return -1;
                }
                if(o.x<x) {
                	return 1;
                }
                return 0;

          }
         public String toString(){
            return (x+" "+y);
        }
  }

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Application {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nk = parse(scanner.nextLine().split(" "));
        int[] a = parse(scanner.nextLine().split(" "));

        System.out.println(solve(a, nk[1]));
    }

    private static long solve(int[] a, int k) {
        long res = 0;
        Map<Long, List<Integer>> dict = new HashMap<>();
        dict.put(0L, Collections.singletonList(0));

        long sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
            if (!dict.containsKey(sum)) dict.put(sum, new ArrayList<>());
            dict.get(sum).add(i);

            for (int j = 0; j < 50; j++) {
                try {
                    long lookingFor = sum - pow(k, j);

                    if (dict.containsKey(lookingFor)) {
                        List<Integer> indices = dict.get(lookingFor);
                        res += indices.size();
                    }
                }
                catch (ArithmeticException e) {
                    break;
                }
            }
        }

        return res;
    }

    private static long pow(int k, int pow) {
        long res = 1;

        while (pow > 0) {
            res = Math.multiplyExact(res, k);
            pow--;
        }

        return res;
    }

    private static int[] parse(String[] line) {
        int[] res = new int[line.length];
        for (int i = 0; i < line.length; i++)
            res[i] = Integer.valueOf(line[i]);
        return res;
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Application {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nk = parse(scanner.nextLine().split(" "));
        int[] a = parse(scanner.nextLine().split(" "));

        System.out.println(solve(a, nk[1]));
    }

    private static long solve(int[] a, int k) {
        long res = 0;
        Map<Long, List<Integer>> dict = new HashMap<>();
        List<Integer> list = new ArrayList<>();
        list.add(0);
        dict.put(0L, list);

        Set<Long> pows = new HashSet<>();
        for (int i = 0; i < 50; i++) {
            try {
                long pow = pow(k, i);
                pows.add(pow);
            }
            catch (Exception e) {
                break;
            }
        }

        long sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
            if (!dict.containsKey(sum)) dict.put(sum, new ArrayList<>());
            dict.get(sum).add(i);

            for (long pow : pows) {
                long lookingFor = sum - pow;

                if (dict.containsKey(lookingFor)) {
                    List<Integer> indices = dict.get(lookingFor);
                    res += indices.size();
                }
            }
        }

        return res;
    }

    private static long pow(int k, int pow) {
        long res = 1;

        while (pow > 0) {
            res = Math.multiplyExact(res, k);
            pow--;
        }

        return res;
    }

    private static int[] parse(String[] line) {
        int[] res = new int[line.length];
        for (int i = 0; i < line.length; i++)
            res[i] = Integer.valueOf(line[i]);
        return res;
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Application {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nk = parse(scanner.nextLine().split(" "));
        int[] a = parse(scanner.nextLine().split(" "));

        System.out.println(solve(a, nk[1]));
    }

    private static long solve(int[] a, int k) {
        long res = 0;
        Map<Long, List<Integer>> dict = new HashMap<>();
        List<Integer> list = new ArrayList<>();
        list.add(0);
        dict.put(0L, list);

        long sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
            if (!dict.containsKey(sum)) dict.put(sum, new ArrayList<>());
            dict.get(sum).add(i);

            Set<Long> tested = new HashSet<>();
            for (int j = 0; j < 50; j++) {
                try {
                    if (tested.contains(pow(k, j)))
                        continue;

                    long lookingFor = sum - pow(k, j);
                    tested.add(pow(k, j));

                    if (dict.containsKey(lookingFor)) {
                        List<Integer> indices = dict.get(lookingFor);
                        res += indices.size();
                    }
                }
                catch (ArithmeticException e) {
                    break;
                }
            }
        }

        return res;
    }

    private static long pow(int k, int pow) {
        long res = 1;

        while (pow > 0) {
            res = Math.multiplyExact(res, k);
            pow--;
        }

        return res;
    }

    private static int[] parse(String[] line) {
        int[] res = new int[line.length];
        for (int i = 0; i < line.length; i++)
            res[i] = Integer.valueOf(line[i]);
        return res;
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Application {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nk = parse(scanner.nextLine().split(" "));
        int[] a = parse(scanner.nextLine().split(" "));

        System.out.println(solve(a, nk[1]));
    }

    private static long solve(int[] a, int k) {
        long res = 0;
        Map<Long, List<Integer>> dict = new HashMap<>();
        dict.put(0L, Collections.singletonList(0));

        long sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
            if (!dict.containsKey(sum)) dict.put(sum, new ArrayList<>());
            dict.get(sum).add(i);

            for (int j = 0; j < 50; j++) {
                long lookingFor = sum - pow(k, j);

                if (dict.containsKey(lookingFor)) {
                    List<Integer> indices = dict.get(lookingFor);
                    res += indices.size();
                }
            }
        }

        return res;
    }

    private static long pow(int k, int pow) {
        long res = 1;

        while (pow > 0) {
            res *= k;
            pow--;
        }

        return res;
    }

    private static int[] parse(String[] line) {
        int[] res = new int[line.length];
        for (int i = 0; i < line.length; i++)
            res[i] = Integer.valueOf(line[i]);
        return res;
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Application {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nk = parse(scanner.nextLine().split(" "));
        int[] a = parse(scanner.nextLine().split(" "));

        System.out.println(solve(a, nk[1]));
    }

    private static long solve(int[] a, int k) {
        long res = 0;
        Map<Long, List<Integer>> dict = new HashMap<>();
        List<Integer> list = new ArrayList<>();
        list.add(0);
        dict.put(0L, list);

        long sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
            if (!dict.containsKey(sum)) dict.put(sum, new ArrayList<>());
            dict.get(sum).add(i);

            for (int j = 0; j < 50; j++) {
                try {
                    long lookingFor = sum - pow(k, j);

                    if (dict.containsKey(lookingFor)) {
                        List<Integer> indices = dict.get(lookingFor);
                        res += indices.size();
                    }
                }
                catch (ArithmeticException e) {
                    break;
                }
            }
        }

        return res;
    }

    private static long pow(int k, int pow) {
        long res = 1;

        while (pow > 0) {
            res = Math.multiplyExact(res, k);
            pow--;
        }

        return res;
    }

    private static int[] parse(String[] line) {
        int[] res = new int[line.length];
        for (int i = 0; i < line.length; i++)
            res[i] = Integer.valueOf(line[i]);
        return res;
    }
}


import java.util.Scanner;

public class Application {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nk = parse(scanner.nextLine().split(" "));
        int[] a = parse(scanner.nextLine().split(" "));

        System.out.println(solve(a, nk[1]));
    }

    private static int solve(int[] a, int k) {
        SegmentTree tree = new SegmentTree(a.length);
        for (int i = 0; i < a.length; i++)
            tree.set(i, a[i]);

        int res = 0;
        for (int j = 0; j < 20; j++) {
            long val = pow(k, j);
            for (int from = 0; from < a.length; from++) {
                for (int to = 0; to < a.length; to++) {
                    if (tree.sum(from, to) == val)
                        res++;
                }
//                // Binary search.
//                int l = 0, r = a.length - 1;
//                while (l <= r) {
//                    int m = (l + r) / 2;
//                    long v = tree.sum(from, m);
//                    if (val == v) {
//                        System.out.println("[" + from + ", " + m + "] = " + val);
//                        res++;
//                        break;
//                    }
//                    else if (val < v)
//                        r = m - 1;
//                    else
//                        l = m + 1;
//                }
            }
        }

        return res;
    }

    private static long pow(int k, int pow) {
        long res = 1;

        while (pow > 0) {
            res *= k;
            pow--;
        }

        return res;
    }

    private static int[] parse(String[] line) {
        int[] res = new int[line.length];
        for (int i = 0; i < line.length; i++)
            res[i] = Integer.valueOf(line[i]);
        return res;
    }

    private static class SegmentTree {

        private final int n;

        private final long[] tree;

        public SegmentTree(int n) {
            this.n = n;
            this.tree = new long[n * 4 + 1];
        }

        public void set(int idx, int val) {
            int l = 0, r = n - 1, node = 1;
            while (node < tree.length) {
                tree[node] += val;
                int m = (l + r) / 2;
                if (idx <= m) {
                    r = m;
                    node = node * 2;
                }
                else {
                    l = m + 1;
                    node = node * 2 + 1;
                }
            }
        }

        public long sum(int from, int to) {
            return sum(from, to, 0, n - 1, 1);
        }

        private long sum(int from, int to, int l, int r, int node) {
            if (from <= l && to >= r)
                return tree[node];

            if (to < l || from > r)
                return 0;

            int m = (l + r) / 2;
            return sum(from, to, l, m, node * 2) + sum(from, to, m + 1, r, node * 2 + 1);
        }
    }
}