結果

問題 No.3441 Sort Permutation 2
コンテスト
ユーザー ああ
提出日時 2026-03-23 12:05:28
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 450 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 364 ms
コンパイル使用メモリ 85,204 KB
実行使用メモリ 115,040 KB
最終ジャッジ日時 2026-03-23 12:05:46
合計ジャッジ時間 8,530 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def gcd(x,y):
	if not min(x,y):
		return max(x,y)
	while x%y:
		x,y=y,x%y
	return y
		

n=int(input())
p=list(map(lambda x:int(x)-1,input().split()))
a=[0]*n
ans=[0]*(n)
for i in range(n):
	if a[i]:
		continue
	if i==p[i]:
		continue
	c=0;f=0;d=i
	while not a[d]:
		a[d]=1;c=gcd(c,abs(d-p[d]));f+=1
		d=p[d]
	f-=1
	for j in range(1,int(c**0.5)+1):
		if c%j:
			continue
		d=c//j
		ans[j]+=f
		if j!=d:
			ans[d]+=f
for i in range(1,n):
	print(ans[i])
0