結果

問題 No.2797 Square Tile
ユーザー vwxyz
提出日時 2024-06-28 23:50:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,768 KB
最終ジャッジ日時 2024-06-28 23:50:10
合計ジャッジ時間 2,832 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

A,B=map(int,input().split())
def solve(A,B):
    L=A*A+B*B
    if A<B:
        retu=solve(B,A)
        retu=retu[L:]+retu[:L]
    else:
        g=math.gcd(A,B)
        if g>=2:
            retu=solve(A//g,B//g)
            le=len(retu)
            retu0=retu[:le//2]
            retu1=retu[le//2:]
            retu=[]
            a,b=A//g,B//g
            l=a*a+b*b
            for x,y in retu0+retu1:
                for i in range(g):
                    for j in range(g):
                        retu.append(((x*g+i*l*g)%L,(y*g+j*l*g)%L))
        else:
            retu=[]
            for x in range(L):
                retu.append((x*B%L,x*A%L))
            for x in range(L):
                retu.append(((x*B+A)%L,(x*A+A-B)%L))
    return retu
ans_lst=solve(A,B)
for x,y in ans_lst:
    print(x,y)
0