結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー yuusanlondonyuusanlondon
提出日時 2020-10-09 23:21:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,144 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 86,132 KB
実行使用メモリ 75,656 KB
最終ジャッジ日時 2023-09-27 19:44:47
合計ジャッジ時間 2,801 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,988 KB
testcase_01 AC 74 ms
70,752 KB
testcase_02 AC 76 ms
70,992 KB
testcase_03 AC 75 ms
70,596 KB
testcase_04 AC 74 ms
70,916 KB
testcase_05 AC 87 ms
75,324 KB
testcase_06 AC 86 ms
75,600 KB
testcase_07 AC 82 ms
75,140 KB
testcase_08 AC 108 ms
75,480 KB
testcase_09 AC 114 ms
75,520 KB
testcase_10 AC 106 ms
75,492 KB
testcase_11 AC 110 ms
75,472 KB
testcase_12 AC 109 ms
75,656 KB
testcase_13 WA -
testcase_14 AC 232 ms
75,148 KB
testcase_15 AC 102 ms
75,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Python3 program to calculate 
# Euler's Totient Function
def phi(n):
     
    # Initialize result as n
    result = n; 
 
    # Consider all prime factors
    # of n and subtract their
    # multiples from result
    p = 2; 
    while(p * p <= n):
         
        # Check if p is a 
        # prime factor.
        if (n % p == 0): 
             
            # If yes, then 
            # update n and result
            while (n % p == 0):
                n = int(n / p);
            result -= int(result / p);
        p += 1;
 
    # If n has a prime factor
    # greater than sqrt(n)
    # (There can be at-most 
    # one such prime factor)
    if (n > 1):
        result -= int(result / n);
    return result;
# This code is contributed 
# by mits
t=int(input())
for _ in range(t):
  n=int(input())
  if n==1:
    print(0)
    continue
  totient=phi(2*n-1)
  while True:
    flag=0
    count=2
    while count*count<=totient:
      if totient%count==0 and pow(2,totient//count,2*n-1)==1:
        totient=totient//count
        break
      count+=1
    if count*count>totient:
      flag=1
    if flag==1:
      break
  print(totient)
0