結果
問題 | No.546 オンリー・ワン |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:00:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,741 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 67,848 KB |
最終ジャッジ日時 | 2025-03-20 21:00:40 |
合計ジャッジ時間 | 1,233 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
ソースコード
import sysfrom math import gcddef main():input = sys.stdin.read().split()N = int(input[0])L = int(input[1])H = int(input[2])C = list(map(int, input[3:3+N]))answer = 0for i in range(N):ci = C[i]A = H // ci - (L - 1) // ciif A <= 0:continuehas_one = FalseD = []for j in range(N):if j == i:continuecj = C[j]g = gcd(ci, cj)dj = cj // gif dj == 1:has_one = TruebreakD.append(dj)if has_one:continuem = len(D)if m == 0:answer += Acontinuek_start = (L + ci - 1) // cik_end = H // ciif k_start > k_end:continueB = 0for mask in range(1, 1 << m):bits = bin(mask).count('1')current_lcm = 1valid = Truefor idx in range(m):if mask & (1 << idx):d = D[idx]g = gcd(current_lcm, d)new_lcm = (current_lcm // g) * dif new_lcm > k_end:valid = Falsebreakcurrent_lcm = new_lcmif not valid:continuecnt = (k_end // current_lcm) - ((k_start - 1) // current_lcm)if cnt > 0:if bits % 2 == 1:B += cntelse:B -= cntanswer += (A - B)print(answer)if __name__ == "__main__":main()