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



Sample input:
3 2


Sample output:
9

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    x1, y1, x2, y2 = LI()
    a = x2 - x1
    b = y2 - y1
    print(x2 - b, y2 + a, x1 - b, y1 + a)
    return

#C
def C():
    n, k = LI()
    if k % 2:
        print((n // k)** 3)
    else:
        print(int((n//k)**3 + ((n-k/2)//k+1)**3))
        
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
from collections import Counter
N,K=map(int,input().split())
m=[]
for i in range(1,N+1):
    m.append(i%K)
Cnt=Counter(m)
cnt=0
for a in range(K):
    r=(K-a)%K
    if((2*r)%K==0):
        cnt+=Cnt[r]**2*Cnt[a]
print(cnt)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=(n//k)**3
if k%2==0:
  ans+=(n//(k//2)-n//k)**3
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=0
if k%2==0:
  ans+=(n//k+(1 if n%k>=k//2 else 0))**3
ans+=(n//k)**3
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)


def input(): return sys.stdin.readline().rstrip()


N, K = map(int, input().split())
# 2 * a, 2 * b, 2 * c
if K % 2 == 1:
    print((N // K) ** 3)
else:
    print((N // K) ** 3 + (N // (K // 2) - N // K) ** 3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K % 2 == 1:
    num = N // K
    ans = num ** 3
else:
    K_ = K // 2
    num1 = N // K
    num2 = (N + K - K_) // K
    ans = num1 ** 3 + num2 ** 3

print(ans)

Submission status: Accepted

Solution code:
def sum(n,k):
    sum = 0
    for a in range(1,n+1):
        for b in range(1,n+1):
            for c in range(1,n+1):
                if(a+b)%k == 0:
                    if(a+c)%k == 0:
                        if(b+c)%k == 0:
                            sum += 1

n,k = map(int,input().split())
t0 = 0
t5 = 0 
for a in range(1,n+1):
    #print(a,a/k)
    if(a%k == 0):
        t0 += 1
    elif(a/k)%(0.5)==0:
        t5 += 1
#print(t0,t5)
print(pow(t5,3)+pow(t0,3))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K%2 == 1:
    print((N//K)**3)
else:
    a, b = 0, 0
    for i in range(1, N+1):
        if i%K == 0:
            a += 1
        elif i%K == K//2:
            b += 1
    print(b**3+a**3)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
ans = (N // K) ** 3
if K % 2 == 0:
    ans += ((N - K // 2) // K + 1) ** 3
print(ans)

Submission status: Accepted

Solution code:
import sys

n, k = map(int, sys.stdin.readline().split())

def main():
    c1 = n // k
    if (k & 1): cnt = pow(c1, 3)
    else: c2 = n // (k // 2); cnt = pow(c1, 3) + pow(c2 - c1, 3)
    print(cnt)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # a % kの値で全探索
    n,k = readInts()
    NUM = [0] * k
    for i in range(1,n+1):
        NUM[i%k] += 1
    # NUM[x] = k で割って、x余る数が1以上N以下に何個あるか
    res = 0
    for a in range(k):
        # a % k を決め打つと、 b % K , c % K を取るべき値が一意に決まる
        # a + b, a + c が k の倍数であることから
        # そうして決まったb,cについて、 b + c が K の倍数になっているかどうかをcheck
        
        b = (k-a) % k
        c = (k-a) % k
        if (b+c) %k != 0:
            continue
        res += NUM[a]*NUM[b]*NUM[c]
    print(res)





if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
 
n, k =  map(int, input().split())

if k % 2 == 1:
    ans = (n // k) ** 3
else:
    a, b = 0, 0
    for i in range(1, n+1):
        if i % k == 0:
            a += 1
        if i % k == k // 2:
            b += 1
    ans = a**3 + b**3
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

ans = 0
a = n//k
ans += a*(a-1)*(a-2) + 3*a*(a-1) + a

if k % 2 == 0:
  a = (n-k//2)//k + 1
  ans += a*(a-1)*(a-2) + 3*a*(a-1) + a
  
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
if(K % 2 == 1):
  A = (N // K) ** 3
  print(A)
else:
  A = (N // K) ** 3
  B = ((N + (K//2) ) // K) ** 3
  print(A + B)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
if K % 2 == 1:
    print((N // K )**3)
else:
    print(((N//(K//2))-(N//K))**3 + (N//K)**3)

Submission status: Accepted

Solution code:
n,k= list(map(int,input().split()))

sign = k%2

if sign == 0:
  temp = 0
  for i in range(1,n+1):
    if i%k == k//2:
      temp = temp + 1  
  ans = (n//k)**3 + temp**3
elif sign == 1:
  ans = (n//k)**3
  
print(int(ans))

Submission status: Accepted

Solution code:
N,K=map(int, input().split())

#a,b,c全てKの倍数
#mod　足してKになるようにする→modがK/2
modk=0
modhalf=0
for i in range(1,N+1):
  if i%K==0:
    modk+=1
  if K%2==0 and i%K==(K//2):
    modhalf+=1
    

ans=0
if modk>=1:
  ans+=(modk)**3
if modhalf>=1:
  ans+=modhalf**3

print(ans)
#print(modk, modhalf)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    if k%2 == 1:
        print((n//k)**3)
    else:
        print(((n-k//2)//k+1)**3 + (n//k)**3)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

ans1 = 0
ans2 = 0
if K%2 == 1:
    for i in range(1,N+1):
        if i%K == 0:
            ans1 += 1
            
        ans = ans1**3
else:
    for i in range(1,N+1):
        if i%K == 0:
            ans1 += 1
        if i%K == K//2:
            ans2 += 1
        ans = ans1**3 + ans2**3
            
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    x = sum(2 * i % k == 0 for i in range(1, k))
    a, b = n // k, n % k
    y = sum(2 * i % k == 0 for i in range(k * a + 1, k * a + b + 1))
    c = x * a + y
    ans = (x * a + y) ** 3 + a ** 3
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, k = map(int, readline().split())
  if k&1:
    ans = (n//k)**3
  else:
    kk = k//2
    even = n//k
    odd = n//kk -even
    ans = even**3 + odd**3
  print(ans)
  
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n,k = list(map(int, input().split()))

if k%2==1:
    print((n//k)**3)
else:
    print(int((n//k)**3 + ((n+(k/2))//k)**3))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
if k % 2:
    ans = (n // k) ** 3
else:
    ans = ((n // (k // 2)) - (n // k)) ** 3 + (n // k) ** 3
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

a = n // k
if k % 2 == 1:
    print(a ** 3)

else:
    b = n + (k // 2)
    b = b // k
    print(a ** 3 + b ** 3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

if k % 2 != 0:
    x = n // k
    print(x ** 3)
else:
    x = n // k
    y = 0
    for i in range(1, n + 1):
        if i % k == k // 2:
            y += 1
    print(x ** 3 + y ** 3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

# num[x]:kで割ってxあまる数が1以上N以下に何個あるか
num = [0 for _ in range(k)]
for i in range(1, n + 1):
    num[i % k] += 1

res = 0
for a in range(k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k != 0:
        continue
    res += num[a] * num[b] * num[c]

print(res)

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
ans=0

if K%2!=0:
  n=N//K
  ans+=n*(n-1)*(n-2)+n*(n-1)*3+n
else:
  n=N//K
  ans+=n*(n-1)*(n-2)+n*(n-1)*3+n
  k=K//2
  n1=N//k
  n=n1-n
  ans+=n*(n-1)*(n-2)+n*(n-1)*3+n
print(ans)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n, k = IN()
	rr=0
	if k%2==0:
		pp=(n+(k//2)) // k
		#print(pp,rr)
		rr+=pp**3
		
	pp = n//k
	#print(pp,rr)
	rr += pp**3
	
	print(rr)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())

if k%2==1:
    print((n//k)**3)
    exit()
ans=0
#全部偶数か全部奇数

#偶数k%2==0
ans+=((n//k)**3)
#奇数and 余りが０、k/2
count=0
for i in range(1,n+1):
    if i%k==k//2:
        count+=1
ans+=count**3

print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()

m = [0] * k
for i in range(1, n + 1):
    m[i%k] += 1

ans = 0
for a in range(k):
    b = (k - a) % k
    c = (k - a) % k
    if (b + c) % k != 0:
        continue
    ans += m[a] * m[b] * m[c]

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
freq=[0]*k
for i in range(1,n+1):
    freq[i%k]+=1
ans=0
if k%2==0:
    ans=freq[k//2]**3
ans+=freq[0]**3
print(ans)

Submission status: Accepted

Solution code:
import math

N, K = map(int, input().split())

if K%2==1:
    print((N//K)**3)
else:
    all=N//(K/2)
    even=math.floor(all/2)
    odd=math.ceil(all/2)
    print(even**3+odd**3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ans = (n // k) ** 3
if k % 2 == 0:
    ans += ((n + (k // 2)) // k) ** 3
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
print((n//k)**3 + (1-k%2)*((n - k//2)//k+1)**3)

Submission status: Accepted

Solution code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
from fractions import gcd

# import itertools

# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))

    ans = 0
    if k % 2 == 0:
        odd = (n + (k // 2)) // k
        even = n // k
        ans = (odd ** 3 + even ** 3)
    else:
        cnt = n // k
        ans = cnt ** 3

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

ans = (N//K) ** 3
if K % 2 == 0: ans += (N//K + (1 if N%K >= K//2 else 0))**3
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())

if K%2==1:
  print((N//K)**3)
else:
  print((N//K)**3+((N+K//2)//K)**3)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ans=(n//k)*(n//k)*(n//k)
if k%2==0:
    p=n//(k//2)-n//k
    ans+=p*p*p
print(ans)

Submission status: Accepted

Solution code:
#108c
import math
N,K = map(int, input().split())

#a,b,cが全て
# = K/2*(2n+1) …(1) 0 <= n , K/2*(2n+1) <= N
# = K*n  　　　…(2) 0 < n  , K*n <=N
#ならOK。ただし、a,b,cは整数なのでK/2が整数でなければ(1)はNG

if K == 1:
    #すべてのa,b,cがOK
    print(pow(N,3))
else:
    #(2)はKに関わらずOK
    #K*n <= N
    #n <= N/K
    #print("(2)K*n")
    #print([i*K for i in range(1,1+int(N/K))])
    ans = pow(int(N/K),3)
    
    if K%2 == 0:
        #(1)も考えてやる
        #K/2*(2n+1) <= N
        #K*(2n+1) <= 2N
        #2n+1 <= 2N/K
        #2n <= 2N/K - 1
        #n <= N/K - 1/2
        n_limit = int(N/K - 1/2)
        #print("(1)K/2*(2n+1)")
        if K/2 <= N:
            #print([int((K/2)*(1+(2*i))) for i in range(0,n_limit + 1)])
            ans += pow(n_limit + 1,3) #n = 0の時もOKなので+1
    
    print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,(input().split()))
ans = 0
for i in range(1,N+1):
    if 2*i%K == 0:
        ans += ((N+i)//K-(i//K+1)+1)**2
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
N,K=map(int, input().split())

num = [0 for k in range(K)]

# Nの範囲の中で、Kで割った時のあまりがxになる数がどれくらいあるのかをカウントする
for n in range(1, N+1):
  num[n%K] += 1

ans = 0

for a in range(len(num)):
  b = (K-a) % K
  c = (K-a) % K
  if (b + c) % K == 0:
    ans += num[a] * num[b] * num[c]

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
print((N // K) ** 3 if K % 2 else (N // K) ** 3 + ((N + K // 2) // K) ** 3)

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N,K=map(int,input().split())
    if K%2==1:
        print((N//K)**3)
    else:
        cnt=0
        for i in range(1,N+1):
            if 2*(i%K)==K:
                cnt+=1
        print(cnt**3+(N//K)**3)




resolve()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,K=map(int,readline().split())

    if K%2!=0:
        print((N//K)**3)
    else:
        count=0
        L=K//2
        count+=(N//L-N//K)**3
        count+=(N//K)**3
        print(count)
        
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
'''
（１）2つの数の和がKの倍数になる条件
aとbがともにKの倍数である
aとbの mod K の和がKの倍数である
（２）3つの数の内、どの2つを足してもKの倍数になる条件
3つの数全てがKの倍数である
3つの数全てのmod K がK/2である
（３）Kが奇数の時、
3つの数全てがKの倍数である
Kが偶数の時、
3つの数全てがKの倍数である
3つの数全てのmod K がK/2である
を満たす数を数え上げて、その数を3乗（重複を許した3つの数の順列）
'''
n,k=map(int,input().split())
s=n//k
t=0
if k%2==0:
  t=(n+k//2)//k
print(s*s*s+t*t*t)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
ans=0
if K%2==0:
  A=[]
  B=[]
  for i in range(1,N+1):
    if i%K==0:
      A.append(i)
    elif i%K==K//2:
      B.append(i)
  ans=(len(A))**3+(len(B))**3
else:
  C=[]
  for i in range(1,N+1):
    if i%K==0:
      C.append(i)
  ans=(len(C))**3
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, K = map(int, input().split())
    if K % 2 == 0:
        even = N // K
        odd = N // (K // 2) - even
        print(odd ** 3 + even ** 3)
    else:
        print((N // K) ** 3)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
if k % 2 == 1:
    count = n//k
    print(count**3)
else:
    a = (n//k)**3
    count = 0
    for i in range(n//k+1):
        if k*i+k//2 <= n:
            count += 1
    print(count**3+a)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
if k % 2: print((n // k) ** 3)
else: print((n // k) ** 3 + (n // (k // 2) - n // k) ** 3)

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
print((n//k)**3 + (n//(k//2) - n//k)**3) if k % 2 == 0 else print((n//k)**3)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())

if K % 2 == 0:
    cnt1,cnt2 = 0,0
    for n in range(1,N+1):
        if n % K == 0:
            cnt1 += 1
        if n % K == (K // 2):
            cnt2 += 1
    print(cnt1 ** 3 + cnt2 ** 3)
else:
    cnt1 = 0
    for n in range(1,N+1):
        if n % K == 0:
            cnt1 += 1
    print(cnt1 ** 3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

abc1 = N//K
abc2 = (N+K//2)//K

if K%2 == 1 :
    print(abc1**3)
else :
    print(abc1**3 + abc2**3)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K % 2 == 0:
    ans = (N // K)**3 + ((N - K // 2) // K + 1)**3
else:
    ans = (N // K)**3
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())

ans = (N//K)**3
if K%2 == 0:
    N += K//2
    ans += (N//K)**3
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=n//k
b=(n+(k//2))//k
if k%2==0:
    print(a**3+b**3)
else:
    print(a**3)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
if(K%2==1):
    print((N//K)**3)
else:
    print((N//K)**3+(N//K+1)**3 if N%K>=K//2 else (N//K)**3*2)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
s=n//k
t=0
if k%2==0:
  t=(n+k//2)//k
print(s*s*s+t*t*t)

Submission status: Accepted

Solution code:
def submit():
    n, k = map(int, input().split())

    if k % 2:
        count = sum([1 for c in range(1, n + 1) if c % k == 0])
        print(count ** 3)
    else:
        count_1 = sum([1 for c in range(1, n + 1) if c % k == 0])
        count_2 = sum([1 for c in range(1, n + 1) if c % k == k // 2])
        print(count_1 ** 3 + count_2 ** 3)


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
def main():
  import math
  n,k=map(int,input().split())
  ans=pow(((2*n)//k)//2,3)+pow(math.ceil(((2*n)//k)/2),3) if k%2==0 else pow(n//k,3)
  print(ans)
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
n = sum([1 for x in range(K, N + 1, K)])
if K % 2 == 1:
    print(n ** 3)
else:
    m = sum([1 for x in range(K // 2, N + 1, K)])
    print(n ** 3 + m ** 3)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, K = map(int, input().split())
    ans = (N // K) ** 3

    if K % 2 == 0:
        k2 = K // 2
        ans += (1 + (N - k2) // K) ** 3
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

if K % 2 == 0:
    print((N//K)**3 + ((2*N//K - N//K) ** 3 ))
else:
    print((N//K)**3)

Submission status: Accepted

Solution code:
def main():
    n, k = [int(e) for e in input().split()]

    cnt1, cnt2 = 0, 0
    if k%2 == 1:
        for i in range(1, n + 1):
            if i%k == 0:
                cnt1 += 1
    else:
        for i in range(1, n + 1):
            if i%k == 0:
                cnt1 += 1
            elif i%(k//2) == 0:
                cnt2 += 1

    ans = cnt1**3 + cnt2**3
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
print((N//K)**3+(K%2<1)*(2*N//K-N//K)**3)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
if K%2 == 0:
    print((N//K)**3+((2*N)//K-N//K)**3)
else:
    print((N//K)**3)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
f = n // k
if k % 2:
    print(f ** 3)
else:
    h = n // (k // 2) - f
    print(f ** 3 + h ** 3)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = (n//k)**3
if k%2==0:ans += ((n+k//2)//k)**3
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
cnt = 0
count = 0
if k % 2 == 1:
    for i in range(1,n+1):
        if i % k == 0:
            cnt += 1
    print(cnt**3)
else:
    for i in range(1,n+1):
        if i % k == 0:
            cnt += 1
        if i % k == (k//2):
            count += 1
    print((count**3) + (cnt**3) )

Submission status: Accepted

Solution code:
import numpy as np
N,K = [int(i) for i in input().split()]
nums = np.arange(1,N+1)
a =nums[nums%K==0]
ans = len(a)**3
if K%2 == 0:
  a = nums[nums%K==K/2]
  ans += len(a)**3
  
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys


N,K = map(int,input().split())
#%%
ans = 0
for a in range(1,N+1):
    b = K-a%K
    c = K-a%K
    if b==0 or c==0:
        continue
    if (b+c)%K==0:
        if N%K>=b:
            tmpb = (N+K-1)//K
        else:
            tmpb = N//K
        if N%K>=c:
            tmpc = (N+K-1)//K
        else:
            tmpc = N//K
        ans += tmpb*tmpc

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

if k%2!=0:
    factor = n//k
    print(factor**3)
else:
    factor1 = n//k
    res1 = factor1**3
    
    factor2 = 0
    for i in range(1, n+1):
        if (i %(k//2)==0) and (i%k!=0):
            factor2 += 1
    res2 = factor2**3
    print(res1 + res2)

Submission status: Accepted

Solution code:
n, k = map(int,input().split()) 
l = [int(_) for _ in range(1,n+1)]
#print(l)

a = 0
for i in range(n):
    if l[i] % k == 0:
        a += 1
#print(a)

b = 0
for j in range(n):
    if l[j] % k == k/2:
        b += 1
#print(b)

if k % 2 == 1:
    print(a**3)
else:
    print(a**3 + b**3)

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
# 2 * (a+b+c) がKの倍数
# Kが2の時は全て偶数か、全て奇数
# Kが2ではない時、全てKの倍数または全て(K//2）の半公倍数
if K == 2:
    odd = (N+1) // 2
    even = N // 2
    answer = odd ** 3 + even ** 3
else:
    num = N // K    
    answer = num ** 3
    if K % 2 == 0:
        num2 = N // (K//2)
        num2 -= num
        answer += num2 ** 3

print(answer)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = n // k

if k % 2 == 0:
    b = 0
    for i in range(1, n+1):
        if i % k == k // 2:
            b += 1
    print(a ** 3 + b ** 3)
else:
    print(a ** 3)

Submission status: Accepted

Solution code:
n, k = map(int,  input().split())
ans = 0
l1 = [i for i in range(1, n+1) if i % k == 0]
n1 = len(l1)
ans += n1 ** 3
if k % 2 == 0:
    l2 = [i for i in range(1, n+1) if i % k == k // 2]
    n2 = len(l2)
    ans += n2 ** 3
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())

num = [0]*k
#1以上n以下の数において，kで割った余りがxになるような数が何個あるか
for i in range(1,n+1):
    num[i%k] += 1

res = 0
for a in range(k):
    b = (k-a)%k
    c = (k-a)%k
    if (b+c)%k!=0: pass
    else: res += num[a] * num[b] * num[c]
print(res)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc108/tasks/arc102_a
# ちょっと難しい
# 情報を整理すると以下の条件が整理される
# aに関する必要条件 2aはKの倍数。
# aが決定したとき(Aとする)のbとc必要十分条件、b=xK-Aを満たす数字 where xは整数、bは[1,N]
# 以上の条件を満たすものを数えればいいのか？


N, K = map(int, input().split())


def f(A):
    # Aが与えられたとき、必要十分条件を満たすbはいくつあるのか
    # 1+A<=xK<=N+A を満たす xの個数を知りたい
    # N+A以下の整数でKの倍数はいくつある？ - AまでにKの倍数はいくつある？
    nb = (N + A) // K - A // K
    return nb * nb


ans = 0
for i in range(1, N + 1):
    if (2 * i) % K == 0:
        ans += f(i)
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

# a, b, cいずれもkの倍数か、kが偶数かつa, b, cをkで割った余りが等しい
ans = (n//k)**3
if k%2 == 0:
    ans += (len(range(k//2, n+1, k)))**3
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
count = 0
if k%2 == 1:
    for i in range(1,n+1):
        if i%k==0:
            count += 1
    print(count**3)
else:
    half = 0
    for i in range(1,n+1):
        if i%k==0:
            count += 1
        elif i%k==k//2:
            half += 1
    #print(count, half)
    print((count**3)+(half**3))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())

if k % 2 == 1:
    ans = pow(n // k, 3)
    print(ans)
else:
    ans1 = pow(n // k, 3)
    ans2 = 0
    for i in range(1, n + 1):
        if i % k == k / 2:
            ans2 += 1
    print(ans1 + pow(ans2, 3))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
if k%2==1:
    print((n//k)**3)
else:
    result = (n//k)**3
    result += ((n//(k//2))//2+(n//(k//2))%2)**3
    print(result)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
div = N // K
if K % 2 == 1:
    print(div**3)
else:
    if div * K + K // 2 <= N:
        print(div**3 + (div + 1)**3)
    else:
        print(2 * div**3)

Submission status: Accepted

Solution code:
S = input().split(" ")
n = int(S[0])
k = int(S[1])

def calculate(n,k):
    if k % 2 == 0:
        #选取所有能被K整除的数
        s1 = n // k
        s2 = 0
        for i in range(1,n+1):
            if i % k == k/2:
                s2 = s2 + 1
        return s1**3 + s2**3
    else:
        s1 = n // k
        return s1**3

result = calculate(n,k)

print(result)

Submission status: Accepted

Solution code:
from collections import Counter


N, K = map(int, input().split())
if K > 2 * N:
    print(0)
    exit()
else:
    x0 = N // K
    x2 = (N - K // 2) // K  + 1 if K % 2 == 0 else 0

    ans = 0
    ans += x0 ** 3
    # print(ans)
    ans += x2 ** 3
    print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())

nums = [0] * K
for i in range(1, N + 1):
    nums[i % K] += 1

ans = 0
for i in range(K):
    b = (K - i) % K
    c = (K - i) % K
    if (b + c) % K != 0: continue

    ans += nums[i] * nums[b] * nums[c]

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce
from operator import add,sub,mul,truediv
from fractions import gcd
import itertools 

n,k = map(int,input().split())

x = [0]*k

for i in range(1,n+1):
    x[i%k] = x[i%k]+1


ans = x[0]*x[0]*x[0]

for i in range(1,k):
    b = i%k #決め打ち
    a = (k-b) # 必要なあまりを計算
    c = (k-b) # 必要なあまりを計算
    if((a+c)%k != 0):continue
    ans  = ans + x[a] * x[b] * x[c]

print(ans)

Submission status: Accepted

Solution code:
def main():
    n,k = map(int, input().split())

    ans = (n//k)**3
    if k%2 == 0:
        ans += ((n+k//2)//k)**3
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = [int(x) for x in input().split()]

if k % 2 == 1:
    print((n//k)**3)
else:
    if n % k >= k // 2:
        print((n//k+1)**3 + (n//k)**3)
    else:
        print((n//k)** 3 * 2)

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce
from operator import add,sub,mul,truediv
from fractions import gcd
import itertools 

n,k = map(int,input().split())


num = [0]*k

for i in range(1,n+1):
    num[i%k] = num[i%k]+1

ans = 0

for a in range(k):
    b = (k-a)%k
    c = (k-a)%k
    if (b+c)%k != 0:
        continue
    ans = ans + num[a]*num[b]*num[c]


print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
def even_cnt(x): #(a,b,c)a,b,c<=xであってa+b,b+a,c+aのいずれも偶数となる組の数
    if x%2==0:
        s,t=x//2,x//2
    else:
        s,t=x//2,x//2+1
    return s**3+t**3

if k%2!=0:
    print((n//k)**3)
else:
    k//=2
    print(even_cnt(n//k))