Problem:
Score : 300 points

Problem Statement

You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.
The order of a,b,c does matter, and some of them can be the same.

Constraints

1 \leq N,K \leq 2\times 10^5

N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.

Sample Input 1

3 2

Sample Output 1

9

(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.

Sample Input 2

5 3

Sample Output 2

1

Sample Input 3

31415 9265

Sample Output 3

27

Sample Input 4

35897 932

Sample Output 4

114191

Solution in Rust (1.15.1) (judge verdict: Time Limit Exceeded)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
fn main() {
    proconio::input! {
        n: i64,
        k: i64,
    }
    let k_mults = (k..=2 * n).step_by(k as usize).collect::<Vec<_>>();
    // a + b = x;
    // b + c = y;
    // a + c = z;
    //
    // a = (x + z - y) / 2
    // b = (x + y - z) / 2
    // c = (y + z - x) / 2
    let mut count = 0usize;
    for i0 in 0..k_mults.len() {
        let x = k_mults[i0];
        for i1 in 0..=i0 {
            let y = k_mults[i1];
            for i2 in 0..=i1 {
                let z = k_mults[i2];
                let b2 = x + y - z;
                if b2 <= 0 {
                    break;
                }
                if n * 2 < b2 || b2 % 2 != 0 {
                    continue;
                }
                let a2 = x + z - y;
                if a2 <= 0 || n * 2 < a2 || a2 % 2 != 0 {
                    continue;
                }
                let c2 = y + z - x;
                if c2 <= 0 || n * 2 < c2 || c2 % 2 != 0 {
                    continue;
                }
                if a2 == b2 && b2 == c2 {
                    count += 1;
                } else if a2 == b2 || a2 == c2 || b2 == c2 {
                    count += 3;
                } else {
                    count += 6;
                }
            }
        }
    }
    println!("{}", count);
}
*/

fn main() {
    let exe = "/tmp/bin4980EC4B";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";