Шрифт:
Закладка:
23| . .return True
24|
25|num = 0
26|def divisor(m):
27| . .global num
28| . .for c in L:
29| . . . .k = m // c
30| . . . .if k * c == m:
31| . . . . . .num = c
32| . . . . . .return k
33|
34|def decompose(m): # разложение на сомножители
35| . .s = ''
36| . .while m > 1:
37| . . . .m = divisor(m)
38| . . . .s = s + str(num)+'*'
39| . .return s[:-1]
40|
41|for n in range(3,10000000):
42| . .if is_prime(n):
43| . . . .L.append(n)
44| . . . .s = decompose(n-1)+ ' '+str(n)+' '+decompose(n+1)
45| . . . .#List.append('---')
46| . . . .List.append(s)
47|
48|for i in List:
49| . .if i.find('2*3') == -1:
50| . . . .print(i)
51|
52|#SaveList(List)
53|
54|t1 = time.time()
55|print('Time required :', t1 - t0)
56|print('Done!')
57|
58|# for n in range(3,10000000):
59|# Time required : 1540.0686304569244 = 25,666 min
////////////
04.08.23
prostoe6_a.txt
Проверяется окружение простого числа на делимость на 3.
1|#!/usr/bin/env python
2|# -*- codning: utf-8 -*-
3|import math, time
4|t0 = time.time()
5|
6|def is_prime(n):
7| . .if n <= 1:
8| . . . .return False
9| . .if n % 2 == 0:
10| . . . .return n == 2
11|
12| . .max_div = math.floor(math.sqrt(n))
13| . .for i in range(3, 1 + max_div, 2):
14| . . . .if n % i == 0:
15| . . . . . .return False
16| . .return True
17|
18|for n in range(3,100000000):
19| . .if is_prime(n):
20| . . . .#print(n)
21| . . . .if (n-1) % 3 != 0:
22| . . . . . .if (n+1) % 3 != 0:
23| . . . . . . . .print(n)
25|
26|t1 = time.time()
27|print('Time required :', t1 - t0)
28|print('Done!')
29|
30|# for n in range(3,10000000):
31|# Time required : 43.06231665611267
32|
33|# for n in range(3,100000000):
34|# Time required : 1084.299929857254 18 MIN
---
Такие вот дела.