n, k = gets.split.map(&:to_i)

#p [n,k].inspect

alter_k = k%2==1 ? k : k/2

candidates = (1..n).to_a.keep_if {|e| e%alter_k==0 }

if k%2==1
  p candidates.size ** 3 and exit
end

results = []
candidates.each do |a|
  candidates.each do |b|
    candidates.each do |c|
#      results.push([a,b,c]) if (a+b)%k==0 && (b+c)%k==0 && (a+c)%k==0
      results.push([a,b,c]) if a%k == b%k && a%k==c%k
    end
  end
end

p results.size
