Arkady and his friends love playing checkers on an n × n field. The rows and the columns of the field are enumerated from 1 to n.

The friends have recently won a championship, so Arkady wants to please them with some candies. Remembering an old parable (but not its moral), Arkady wants to give to his friends one set of candies per each cell of the field: the set of candies for cell (i, j) will have exactly (i^2 + j^2) candies of unique type.

There are m friends who deserve the present. How many of these n × n sets of candies can be split equally into m parts without cutting a candy into pieces? Note that each set has to be split independently since the types of candies in different sets are different.

Input

The only line contains two integers n and m (1 ≤ n ≤ 10^9, 1 ≤ m ≤ 1000) — the size of the field and the number of parts to split the sets into.

Output

Print a single integer — the number of sets that can be split equally.

Examples

Input


3 3


Output


1


Input


6 5


Output


13


Input


1000000000 1


Output


1000000000000000000

Note

In the first example, only the set for cell (3, 3) can be split equally (3^2 + 3^2 = 18, which is divisible by m=3).

In the second example, the sets for the following cells can be divided equally: 

  * (1, 2) and (2, 1), since 1^2 + 2^2 = 5, which is divisible by 5; 
  * (1, 3) and (3, 1); 
  * (2, 4) and (4, 2); 
  * (2, 6) and (6, 2); 
  * (3, 4) and (4, 3); 
  * (3, 6) and (6, 3); 
  * (5, 5). 



In the third example, sets in all cells can be divided equally, since m = 1.
//package src;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class idk {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;
	
	public static void main(String args[]) {
		
			int n=scn.nextInt(),m=scn.nextInt();
			if(m==1)
			{System.out.println((long)n*(long)n);
			}
			else
			{
				long arr[]=new long[m],b[]=new long[m],c[]=new long[m];
				for(int i=0;i<m;i++)
					arr[i]=(long)(n/m);
				
				int rem=n%m;
				for(int i=1;i<=rem;i++)
				{
					arr[i]=arr[i]+1;
				}
				
				for(int i=0;i<m;i++)
				{
					b[(i*i)%m]+=arr[i]; 
				}
				
				for(int i=0;i<m;i++){
	                for(int j=0;j<m;j++){
	                    c[(i+j)%m] += b[i]*b[j];
	                }
	            }
				System.out.println(c[0]);
				
			}
			
			
		
	}
	
	public static int binarysearch(Long arr[],int l,int r,int key)
	{
			int mid,ans=r;
		while(l<=r)
		{
			mid=l+(r-l)/2;
			if(arr[mid]==key)
			{
				l=mid+1;
				ans=mid;
			}
			else if(arr[mid]>key)
			{
				r=mid-1;
				ans=r;
			}
			else
			{
				l=mid+1;
			}
			
		}
		
		return ans;
	}
	public static boolean word(String arr[],String str,String ori,HashMap<String, Integer>map,int i,int j)
	{	if(j==str.length())
	{	//System.out.println(str);
		if(str.length()==0)
			return true;
		else
			return false;
	}
		
		String re=ori.substring(i,j);
		System.out.println(re);
		if(map.containsKey(re))
		{	String res=ori.substring(j);
		
			return word(arr, str,ori, map, j, j);
		}
		
			return word(arr, str,ori, map, i, j+1);
			
		
	}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

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

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

}

class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int x=o1.a-o2.a,y=o1.b-o2.b;
		if(y==0)
		{
			if(x>=0)
				return -1;
				else
					return 1;
		}
		else if(y>0)
			return -1;
		else
			return 1;
	}

}
