Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # 素因数分解
- #
- import utime
- def prime_factorize(n):
- a = []
- while n % 2 == 0:
- a.append(2)
- n //= 2
- f = 3
- while f * f <= n:
- if n % f == 0:
- a.append(f)
- n //= f
- else:
- f += 2
- if n != 1:
- a.append(n)
- return a
- if __name__ == '__main__':
- start_time = utime.ticks_ms()
- # CircuitPythonの場合
- # start_time = time.monotonic_ns() // 1000000
- a = prime_factorize(849374738754534871)
- end_time = utime.ticks_ms()
- # CircuitPythonの場合
- # end_time = time.monotonic_ns() // 1000000
- print(a)
- print("{0:.3f} 秒".format((end_time - start_time) / 1000.0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement