python正则表达式判断素数【厉害了】

 

参考:

https://www.cnblogs.com/imjustice/p/check_prime_by_using_regular_expression.html

 

for i in range(101, 200):
    a = re.match('^.?$|^(..+?)\\1+$', '*' * i)
    if a is None:
        print('a=', i)

 

输出结果:

a= 101
a= 103
a= 107
a= 109
a= 113
a= 127
a= 131
a= 137
a= 139
a= 149
a= 151
a= 157
a= 163
a= 167
a= 173
a= 179
a= 181
a= 191
a= 193
a= 197
a= 199

Process finished with exit code 0

 

 

 

posted @ 2018-09-04 11:10  菱花淚硃砂  阅读(323)  评论(0编辑  收藏  举报