1.https://www.lanqiao.cn/problems/19954/learning/?contest_id=214
这道题用快速幂直接秒,而快速幂就是求一个数的次方很大的时候,我们可以把指数分解为二进制的形式,再有a的b*c次方等于a的b次方乘以a的c次方,在用一个数存储一下即可。代码如下:
def qui(x, y):
res = 1
while y:
if y & 1:
res = res * x % mod
y >>= 1
x = x * x % mod
return res//快速幂模板
mod = 24
n, q = map(int, input().split())
a = [0] + list(map(int, input().split()))//加0是为了方便处理
b = dict()//相当于c++里面的映射map
for _ in range(q):
xx = int(input())
if xx not in b:
b[xx] = 1
else:
b[xx] += 1
for i, j in b.items():
for k in range(i, n + 1, i):
a[k] = a[k] * qui(10, j) % mod
print(' '.join(map(str, a[1:])))
2.https://www.lanqiao.cn/problems/19950/learning/?contest_id=214
直接模拟一下即可,代码如下:
for _ in range(int(input())):
a,b,c = map(int,input().split())
m,n = a//c,b//c
if m == 0 or n == 0:
print(0)
elif m == 1:
print(n)
elif n == 1:
print(m)
else:
print((m + n) * 2 - 4)
3.https://www.lanqiao.cn/problems/19952/learning/?contest_id=214
这道题只要把贡献值搞明白就可以。代码如下:
su_m = 0
N = int(input())
a = [0] + list(map(int,input().split()))
for i in range(N+1):
su_m += i * (N - i + 1) * a[i]
print(su_m)
不懂得看图解:
4.https://www.lanqiao.cn/problems/19953/learning/?contest_id=214
这道题和上一题一样,考虑贡献值即可。代码如下:
n = int(input())
a = [0] + list(map(int,input().split()))
su_m = 0
for i in range(n + 1):
if i&1:
su_m += a[i] * (n - i + 1)![]
print(su_m)
(https://img2024.cnblogs.com/blog/3530477/202411/3530477-20241103123339863-1882331792.png)