import timedefone_cycle():num =0for i inrange(1,1000000): num +=ireturn numdefdouble_cycle():num =0for i inrange(1000):for j inrange(1000):num +=i*jreturn num deftriple_cycle():num =0for i inrange(100):for j inrange(100):for k inrange(100):num += i*j*kreturn num if __name__=="__main__":start_time = time.time()for i inrange(100):one_cycle()end_time = time.time()print("one_cycle函数运行时间:",(end_time-start_time)/100)start_time = time.time()for i inrange(100):double_cycle()end_time = time.time()print("double_cycle函数运行时间:",(end_time-start_time)/100)start_time = time.time()for i inrange(100):triple_cycle()end_time = time.time()print("triple_cycle函数运行时间:",(end_time-start_time)/100)
import time
import numbaimport warnings
warnings.filterwarnings('ignore')@numba.jitdefone_cycle():num =0for i inrange(1,1000000): num +=ireturn num@numba.jitdefdouble_cycle():num =0for i inrange(1000):for j inrange(1000):num +=i*jreturn num @numba.jitdeftriple_cycle():num =0for i inrange(100):for j inrange(100):for k inrange(100):num += i*j*kreturn num if __name__=="__main__":start_time = time.time()for i inrange(100):one_cycle()end_time = time.time()print("one_cycle函数运行时间:",(end_time-start_time)/100)start_time = time.time()for i inrange(100):double_cycle()end_time = time.time()print("double_cycle函数运行时间:",(end_time-start_time)/100)start_time = time.time()for i inrange(100):triple_cycle()end_time = time.time()print("triple_cycle函数运行时间:",(end_time-start_time)/100)
🌷🍁 博主猫头虎(🐅🐾)带您 Go to New World✨🍁 🦄 博客首页:
🐅🐾猫头虎的博客🎐《面试题大全专栏》 🦕 文章图文并茂🦖…
T 1 T1 T1求的是有多少个区间的异或和是 k k k的因子, n , k ≤ 1 0 5 n,k \leq 10^5 n,k≤105。
这道题用前缀和维护一下,暴力枚举所有区间就有 80 80 80分。
有一瞬间想过枚举因数,但是脑抽以为要 O ( n ) \mathcal O(n) O(n)枚举&#x…