結果
問題 | No.1255 ハイレーツ・オブ・ボリビアン |
ユーザー |
![]() |
提出日時 | 2020-10-09 23:22:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 187 ms / 2,000 ms |
コード長 | 1,107 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 82,200 KB |
実行使用メモリ | 62,944 KB |
最終ジャッジ日時 | 2024-07-23 08:45:52 |
合計ジャッジ時間 | 1,933 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
ソースコード
# Python3 program to calculate# Euler's Totient Functiondef phi(n):# Initialize result as nresult = n;# Consider all prime factors# of n and subtract their# multiples from resultp = 2;while(p * p <= n):# Check if p is a# prime factor.if (n % p == 0):# If yes, then# update n and resultwhile (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 mitst=int(input())for _ in range(t):n=int(input())totient=phi(2*n-1)while True:flag=0count=2while count*count<=totient:if totient%count==0 and pow(2,totient//count,2*n-1)==1:totient=totient//countbreakcount+=1if count*count>totient:flag=1if flag==1:breakprint(totient)