def recursion(n,k):
global arr
if n < 3:
return
if n == 3:
arr[1][1] = ' '
return
for i in range(k):
for j in range(k):
if(int(n/3) <= i%n < int(n/3)*2) and (int(n/3) <= j%n < int(n/3)*2):
arr[i][j] = ' '
return recursion(int(n/3), k)
n = int(input())
arr = [['*' for col in range(n)]for row in range(n)]
recursion(n, n)
for i in result:
print(''.join(i))
* 출력은 맞는데 시간초과,, 다시 풀어야겠다..
ㄴ 해결 (21.04.23)
import sys
sys.setrecursionlimit(10**6)
def recursion(m):
global arr, n
if m < 3:
return
for i in range(n):
if not (m//3 <= i%m < m//3*2):
continue
for j in range(n):
if(m//3 <= i%m < m//3*2 and m//3 <= j%m < m//3*2):
arr[i][j] = ' '
return recursion(m//3)
m = n = int(input())
arr = [['*' for col in range(n)]for row in range(n)]
recursion(m)
for i in arr:
print(''.join(i))