import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Loc = Tuple!(long, "x", long, "y", long, "h");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

auto charcount(string s)
{
    char current = s[0];
    auto ret = new long[](1);
    foreach (e; s)
    {
        if (e != current)
        {
            ret ~= [0];
            current = e;
        }
        ret[$ - 1]++;
    }
    return ret;
}

void main()
{
    long n, k;
    scan(n, k);
    auto remainder = new long[](k);
    foreach (i; iota(1, n + 1))
        remainder[i % k]++;

    if (k % 2)
    {
        writeln(remainder[0] ^^ 3);
    }
    else
    {
        auto result = remainder[0] ^^ 3;
        result += remainder[k / 2] ^^ 3;
        result.writeln();
    }
}
