var fs = require('fs')

var inputs = fs.readFileSync('/dev/stdin', 'utf8').split(' ')

const n = inputs[0]
const k = inputs[1]

var pairs = []

for (a = 1; a <= n; ++a) {
    for (b = 1; b <= a; ++b) {
        for (c = 1; c <= b; ++c) {
            if ((a + b) % k === 0 &&
                (b + c) % k === 0 &&
                (c + a) % k === 0) {
                pairs.push([a, b, c])
                console.log(pairs.length)
            }
        }
    }
}

sum = 0
for (pair of pairs) {
    d = pair.reduce(
        function(distinct, val) { return distinct.indexOf(val) !== -1 ? distinct : [...distinct, val] },
        []
    )
    switch (d.length){
        case 1:
            sum += 1;
            break
        case 2:
            sum += 3
            break
        case 3:
            sum += 6
    }
}

console.log(sum)
