結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー yuusanlondonyuusanlondon
提出日時 2020-10-09 23:22:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 76,228 KB
最終ジャッジ日時 2023-09-30 14:45:00
合計ジャッジ時間 2,941 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,256 KB
testcase_01 AC 75 ms
71,312 KB
testcase_02 AC 74 ms
71,072 KB
testcase_03 AC 75 ms
71,572 KB
testcase_04 AC 75 ms
71,120 KB
testcase_05 AC 82 ms
76,200 KB
testcase_06 AC 82 ms
76,200 KB
testcase_07 AC 81 ms
76,208 KB
testcase_08 AC 106 ms
76,076 KB
testcase_09 AC 114 ms
76,212 KB
testcase_10 AC 107 ms
76,204 KB
testcase_11 AC 110 ms
76,188 KB
testcase_12 AC 108 ms
76,220 KB
testcase_13 AC 81 ms
76,228 KB
testcase_14 AC 231 ms
76,224 KB
testcase_15 AC 104 ms
76,188 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())
  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