Problem:
 Score : 1000 points    Problem Statement Select any integer N between 1000 and 2000 (inclusive), and any integer K not less than 1 , then solve the problem below.  Problem  We have N sheets of paper.
Write K integers on each of them to satisfy the following conditions:   Each integer written must be between 1 and N (inclusive).  The K integers written on the same sheet must be all different.  Each of the integers between 1 and N must be written on exactly K sheets.  For any two sheet, there is exactly one integer that appears on both.         Input There is no input in this problem.      Output In the first line, print N and K separated by a space.  In the subsequent N lines, print your solution.
The i -th of these lines must contain the K integers written on the i -th sheet, with spaces in between.        Sample Output 3 2
1 2
2 3
3 1  This is an example of a solution for N = 3 and K = 2 .  Note that this output will be judged as incorrect, since the constraint on N is not satisfied.

Solution (Python):
K=38
N=K*(K-1)+1
print(N,K)
ans=[[] for i in range(K)]
for i in range(K):
  L=[j+(K-1)*i+2 for j in range(K-1)]
  ans[i]=L
  L=list(map(str,L))
  L=["1"]+L
  print(" ".join(L))
for i in range(2,K+1):
  for j in range(K-1):
    L=[i]
    for k in range(K-1):
      L.append(ans[k+1][(j+1+(i-2)*k)%(K-1)])
    L=list(map(str,L))
    print(" ".join(L))

Solution (Python):
K=38

N=K**2-K+1

print(N,K)
_res=[[-1 for j in range(K-1)] for i in range((K-1)**2)]
rest=[[-1 for j in range(K-1)] for i in range(K-1)]

id=K
start=0
while N>id:
    for j in range(K-1):
        _res[(K-1)*j+(start+j*((id-1)//(K-1)))%(K-1)][(id-1)//(K-1)-1]=id
    id+=1
    start=(start+1)%(K-1)

rest=[[_res[j][i] for j in range(K-1)] for i in range(K-1)]

ans=[[i for i in range(K)]]
for i in range(K-1):
    for j in range(K-1):
        tmp=[i]+_res[(K-1)*i+j]
        ans.append(tmp)
for i in range(K-1):
    tmp=[K-1]+rest[i]
    ans.append(tmp)

for i in range(N):
    ans[i]=[ans[i][j]+1 for j in range(K)]

for i in range(N):
    print(*ans[i])

def check():
    ids=[[] for i in range(N)]
    for i in range(N):
        ans[i].sort()
        if ans[i][0]<0 or ans[i][-1]>N-1:
            exit(print("WA1"))
        for j in range(1,K):
            if ans[i][j]==ans[i][j-1]:
                exit(print("WA2"))
        for j in range(K):
            ids[ans[i][j]].append(i)
    for i in range(N):
        if len(ids[i])!=K:
            exit(print("WA3"))
    p=set([])
    for i in range(N):
        for j in range(len(ids[i])):
            for k in range(j):
                a,b=ids[i][j],ids[i][k]
                if (a,b) in p:
                    print("WA4")
                    print(ans[a])
                    print(ans[b])
                    exit()

                p.add((a,b))

Solution (Python):
N,K=1407,38
print(N,K)
P=0
ANS=[]
for i in range(K):
  P=[]
  P.append(1)
  for j in range(i*(K-1)+2,i*(K-1)+K+1):
    P.append(j)
  print(*P)
  ANS.append(set(P))
def f(R):
  Q=R[:]
  for i in range(len(Q)):
    Q[i]=Q[i]+i*(K-1)+2
  return Q
for i in range(2,K+1):
  X=[0]*K
  for j in range(K-1):
    X[j+1]=(X[j+1]+(i-2)*j)%(K-1)
  X[0]=i-2
  for j in range(K-1):
    print(*f(X))
    ANS.append(set(f(X)))
    for k in range(1,K):
      X[k]=(X[k]+1)%(K-1)

Solution (Python):
import sys
readline = sys.stdin.readline

N = 1407
K = 38



Ans = [[] for _ in range(N)]
for i in range(N-1):
    Ans[i].append(1+i//(K-1))
for cnt in range(K):
    Ans[N-1].append(1+cnt)

for cnt in range(K+1, N+1):
    st = (cnt-K-1)//(K-1)
    Ans[st].append(cnt)
    sec = (cnt-K-1)%(K-1)
    for j in range(1, K):
        Ans[j*(K-1) + (sec+st*j)%(K-1)].append(cnt)

print(N, K)
print('\n'.join(' '.join(map(str, a)) for a in Ans))

"""
Ans = [frozenset(a) for a in Ans]

for i in range(N):
    for j in range(i):
        assert len(Ans[i] & Ans[j]) == 1, ''
"""

Solution (Python):
import itertools
P = 37
print(P**3//(P-1), P+1)
X = [(a, b, c) for a, b, c in itertools.product(range(P), repeat = 3) if c == 1 or (b, c) == (1, 0) or (a, b, c) == (1, 0, 0)]
for x in X:
    print(*[i + 1 for i, y in enumerate(X) if sum(a * b for a, b in zip(x, y)) % P == 0])

Solution (Python):
P = 37
ANS = []
for a in range(P):
    for b in range(P):
        t = [P*P + (pow(b, P-2, P) if b else 0)]
        for i in range(P):
            t.append((a*P+(b*P+1)*i)%(P*P))
        ANS.append(t)
for a in range(P):
    t = [P*P+P]
    for i in range(P):
        t.append(a+i*P)
    ANS.append(t)
t = []
for i in range(P+1):
    t.append(P*P+i)
ANS.append(t)

print(len(ANS), P+1)
for ans in ANS:
    print(*[a+1 for a in ans])

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

"""
・射影平面 P^2(F_p)
・同一直線上にある点を同じ紙の上に書く
・直線は、P^2(F_p)の点でパラメタライズされる
・(a:b:1) -> a+bp, (a:1:0) -> p^2+a, (1:0:0) -> p^2+p
"""

p = 37; rng = range(p)

inv = [pow(x,p-2,p) for x in range(p)]

def coord_to_idx(x,y,z):
    x %= p; y %= p; z %= p
    if z != 0:
        x *= inv[z]; y *= inv[z]; z = 1; x%=p; y%=p
        return x+y*p+1
    if y != 0:
        x *= inv[y]; x%=p
        return p*p+x+1
    return p*p+p+1

line = []
for a,b in itertools.product(rng,repeat=2):
    
    if a==0 and b==0:
        pts = [coord_to_idx(x,1,0) for x in rng] + [coord_to_idx(1,0,0)]
        line.append(pts)
        continue
    pts = []
    
    pts.append(coord_to_idx(b,-a,0))
    
    if b != 0:
        pts += [coord_to_idx(x,-(a*x+1)*inv[b],1) for x in rng]
    else:
        
        pts += [coord_to_idx(1,x,-a) for x in rng]
    line.append(pts)
for a in rng:
    
    pts = [coord_to_idx(1,-a,x) for x in rng] + [coord_to_idx(0,0,1)]
    line.append(pts)

pts = [coord_to_idx(0,x,1) for x in rng] + [coord_to_idx(0,1,0)]
line.append(pts)

print(p*p+p+1,p+1)
for l in line:
    print(' '.join(map(str,l)))

Solution (Python):

import sys
def input():
	return sys.stdin.readline().strip()

N = 1407
K = 38

num_all = [[0]*K for _ in range(N)]

for i in range(K):
	num_all[0][i] = i + 1
num = 1
for i in range(K):
	for j in range(K - 1):
		num_all[num][0] = i + 1
		num += 1
num = K + 1
for i in range(1, K):
	for j in range(1, K):
		num_all[i][j] = num
		num += 1

for n in range(2, K + 1):
	for j in range(K - 1):
		for i in range(K - 1):
			num = K + 1 + j*(K - 1) + i
			loc = K + (n - 2)*(K - 1) + ((i + j*(n - 2))%(K - 1))
			num_all[loc][j + 1] = num


def list_print(A):
	length = len(A)
	for i in range(length - 1):
		print(A[i], end="")
		print(" ", end="")
	print(A[- 1])

list_print([N, K])
  
for i in range(N):
	list_print(num_all[i])

Solution (Python):
N = 1407; K = 38
ans = []
for i in range(K):
    tmp = [1] + list(range((K-1)*i+2, (K-1)*(i+1)+2))
    ans.append(tmp)
for i in range(1, K):
    for j in range(K-1):
        tmp = [i+1]
        for k in range(K-1):
            tmp.append(K+((j + (i-1)*k) % (K-1))+k*(K-1) + 1)
        ans.append(tmp)
print(N, K)
for l in ans:
    print(*l)

Solution (Python):

N = 1723
K = 42 

print(N, K)

ans = []

l = []
for i in range(K):
    z = [1] + list(range(2+(K-1)*i, 2+(K-1)*i+(K-1)))
    l.append(z[1:])
    ans.append(z)
    print(' '.join(map(str, z)))

for i in range(2, K+1):
    for j in range(K-1):
        z = [i] + [ l[1+k][(j+(i-2)*k)%(K-1)] for k in range(K-1) ]
        ans.append(z)
        print(' '.join(map(str, z)))

count = [0 for v in range(N+1)]
for xs in ans:
    for v in xs:
        count[v] += 1

assert(sum(count) == N*K)
for i in range(1, K+1):
    assert(count[i] == K)