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 C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Globalization;

#if DEBUG
using System.Diagnostics;
#endif

namespace at102c
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;
        const string _delim = "!";


        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
            var testNumber = 0;
            var timer = new Stopwatch();
            foreach (var test in GetTests())
            {

                timer.Start();

                var defaultColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} -->");
                Console.ForegroundColor = defaultColor;
                Console.SetIn(test);


#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

                try
                {
#if DEBUG
                    Solution(testNumber);
#else
                Solution(0);
#endif
                }
                finally
                {
#if DEBUG
#else
                if (_useFileInput)
                {
                    file.Close();
                }
#endif
                }

#if DEBUG
                timer.Stop();

                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine($"<!-- TEST #{testNumber} FINISHED IN {timer.Elapsed.ToString(@"ss\:fff")}-->");
                Console.ForegroundColor = defaultColor;

                timer.Reset();
                testNumber++;
            }
#endif
        }



        static void Solution(int testNumber)
        {
            #region SOLUTION
            var d = ReadIntArray();
            var n = d[0];
            var k = d[1];

            var max = n + n;
            var res = 0L;
            var kN = n / k;

            for (int i = kN; i >= 1; i--)
            {
                var add = i * (i + 1) / 2;
                res += add * 6;
                res -= (i - 1) * 3;
                res -= (i - 1) * 3;
                res -= 5;
            }

            if (k % 2 == 0)
            {
                kN = n / (k / 2);
                kN -= (n / k);

                for (int i = kN; i >= 1; i--)
                {
                    var add = i * (i + 1) / 2;
                    res += add * 6;
                    res -= (i - 1) * 3;
                    res -= (i - 1) * 3;
                    res -= 5;
                }
            }
            

            //for (int i = kN; i >= 1; i--)
            //{
            //    if (i * k > n)
            //    {
            //        continue;
            //    }

            //    var maxPrev = Math.Min(kN - i, i);
            //    var add = maxPrev * (maxPrev + 1) / 2;
            //    res += add * 6;
            //    res -= maxPrev * 3;
            //    if (maxPrev == i)
            //    {
            //        res -=2;
            //    }
            //}

            //for (int i = kN; i >= 1; i--)
            //{
            //    if (i * k > n)
            //    {
            //        continue;
            //    }

            //    var maxPrev = Math.Min((kN - i) * 2 + 1, (i - 1) * 2 + 1);
            //    var add = maxPrev * (maxPrev + 1) / 2;
            //    res += add * 6;
            //    res -= maxPrev * 3;
            //    if (maxPrev == i)
            //    {
            //        res -=2 ;
            //    }
            //}

            Console.WriteLine(res);
            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
        static IEnumerable<TextReader> GetTests()
        {
            var tests = new List<string>();
            var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
            using (var resource = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(resName)))
            {
                while (true)
                {
                    var nextText = new StringBuilder();
                    var endOfFile = false;
                    while (true)
                    {
                        var line = resource.ReadLine();

                        endOfFile = line == null;
                        if (endOfFile)
                        {
                            break;
                        }

                        if (line.Equals(_delim, StringComparison.Ordinal))
                        {
                            break;
                        }

                        nextText.AppendLine(line);
                    }

                    yield return new StringReader(nextText.ToString());

                    if (endOfFile)
                    {
                        break;
                    }
                }
            }
        }
#endif
    }
}