#include <iostream>
using namespace std;

int main(){
	int n, m;
	int counter;
	cin>>m>>n;
	while(!cin.eof()){
		cin>>counter;
	}
	counter = 0;
	
	for(int x=1; x<=m; x++)
		for(int y=x; y<=m; y++)
			for(int z=y; z<=m; z++)
				if(x*x+y*y==z*z){
					counter++;
					//cout<<x<<' '<<y<<' '<<z<<endl;
				}		
	counter += (n-1)*(m+1);//ker grejo vse potence 0*0+0*0=0*0 in 1*1+1*1=1*1
	cout<<counter;

	return 0;
}