快速幂-算法日常练习记录

python自带快速幂算法hhh

504. 转圈游戏

504. 转圈游戏 - AcWing题库

"""
https://www.acwing.com/problem/content/506/
"""


n, m, k, x = map(int, input().split(" "))
part = pow(10, k, n*m)
# print(part)
print((x+part*m)%n)

4968. 互质数的个数

4968. 互质数的个数 - AcWing题库

"""
https://www.acwing.com/problem/content/4971/
"""
from math import gcd
from math import sqrt


def solve(x):
    """求解x的质因数分解"""
    for i in range(2, int(sqrt(x)) + 1):
        if x % i == 0:
            factor.append(i)
            p.append(1)
            x = x // i
            while x % i == 0:
                p[-1] += 1
                x = x // i
    if x != 1:
        factor.append(x)
        p.append(1)


a, b = map(int, input().split(" "))
if a == 1 or b == 0: # 特判
    print(0)
    exit()
MOD = 998244353
factor = []
p = []
solve(a)
# 欧拉函数
a_b1 = pow(a, b-1, MOD)
res = a
for pivot, f in enumerate(factor):
    res = res * ((f - 1) // f)
res = (res * a_b1) % MOD
print(res)

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值