import java.util.Scanner;
public class Test{
public static int getNum(int N,int K){
int count=0;
for(int a=1;a<N;a++){
for(int b=1;b<N;b++){
for(int c=1;c<N;c++){
if((a+b)%K==0&&(b+c)%K==0&&(c+a)%K==0){
count++;
System.out.format("(%d,%d,%d)\n",a,b,c);
}
}
}
}
return count;
}
public static void main(String args[]){
Scanner in=new Scanner(System.in);
System.out.println("请输入两个正整数:");
int N=in.nextInt();
int K=in.nextInt();
System.out.println("符合要求的三元组为:");
System.out.println("共有"+getNum(N,K)+"组");
}
}