摘要: 直觉认为,系统库中自带的幂函数性能优于快速幂 但是C++幂函数不支持模运算,因此在涉及到结果取模时,需要使用自定义的快速幂。 然而python没有这一问题,python中的pow可选择第三个参数,即mod,自带模运算的功能。 经实验,python自带pow确实优于快速幂,然而c++中的pow速度要比 阅读全文
posted @ 2025-06-18 21:52 邓佑孤 阅读(11) 评论(0) 推荐(0)
摘要: from functools import lru_cache @lru_cache(maxsize=None) # 加在函数定义前 def lcm(a, b): return (a * b) // math.gcd(a, b) 简单的缓存 import time def timer(func): 阅读全文
posted @ 2025-06-18 21:24 邓佑孤 阅读(10) 评论(0) 推荐(0)
摘要: #include<bits/stdc++.h> using namespace std; int n; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return (a / g 阅读全文
posted @ 2025-06-18 20:27 邓佑孤 阅读(51) 评论(0) 推荐(0)