C题
签到题。会python的permutations 或者C++的next_permutation就能做。
D题
乍一看很简单,把所有元素折半求最小公倍数lcm,然后求lcm的奇数倍即可。但是有坑:
比如6 4这种情况,lcm=6 但6=61 6=41.5,因此无法满足要求。原因是4折半后为2,导致求得的lcm可以被2整除,如6/2不为半数。去掉这种情况就能AC。
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(200050)
def gcd(x, y):
if x > y:
x, y = y, x
while x:
x, y = y % x, x
return y
def main():
items = sys.version.split()
if items[0] == '3.10.6':
fp = open("in.txt")
else:
fp = sys.stdin
n, m = map(int, fp.readline().split())
a = list(map(int, fp.readline().split()))
for i in range(n):
a[i] = a[i] // 2
gm = a[0]
for i in range(1, n):
g = gcd(a[i], gm)
gm = gm // g * a[i]
for i in range(n):
if (gm // a[i]) % 2 == 0:
print(0)
return
ans = m // gm - (m // (2 * gm))
print(ans)
if __name__ == "__main__":
main()
E题
下面两个很不错的题。
本题考察如何按位置来计数。首先题目可以把f(S,T)f(S,T)f(S,T)转换为求f(S)=S⊕Tf(S)=S \oplus T

文章介绍了Atcoder编程竞赛中的三个问题,涉及Python函数、数学运算(如permutations,gcd,lcm)、整数处理(如去除偶数倍lcm)、异或操作在模式匹配中的应用(KMP),以及巧妙的计数方法。
最低0.47元/天 解锁文章
454

被折叠的 条评论
为什么被折叠?



