結果

問題 No.443 GCD of Permutation
コンテスト
ユーザー
提出日時 2016-11-12 00:18:23
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 771 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 298 ms
コンパイル使用メモリ 77,008 KB
最終ジャッジ日時 2025-12-03 22:41:09
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 WA * 10 TLE * 1 -- * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import permutations
from fractions import gcd

g = input()

digits = sorted(map(eval, str(g)))

if len(set(digits)) == 1:
  print g
elif 1 in digits or (any([x != 0 and x%2 == 0 for x in digits]) and any([x%3 == 0 for x in digits])):
  print 1
else:
  digit_len = len(str(g))
  S = []
  G = g
  sg = str(g)
  for x in xrange(1, digit_len):
    d = int(str(g)[x:] + str(g)[:x])
    G = gcd(G, d)
    if G == 1:
      break
  if G != 1:
    sg = sg[::-1]
    for x in xrange(1, digit_len):
      d = int(sg[x:] + sg[:x])
      G = gcd(G, d)
      if G == 1:
        break
  if G != 1:
    sg = sg[::-1]
    sg = sg[::2] + sg[1::2]
    for x in xrange(1, digit_len):
      d = int(sg[x:] + sg[:x])
      G = gcd(G, d)
      if G == 1:
        break
  print G
0