博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
EularProject 41:最长的n位Pandigital素数问题
阅读量:6970 次
发布时间:2019-06-27

本文共 1592 字,大约阅读时间需要 5 分钟。

Pandigital prime

Problem 41
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
Answer:
7652413
Completed on Thu, 30 Jul 2015, 08:32
Go to the thread for problem 41 in the forum.

首先发现3k和3k-1位的ppandigital肯定能被3整除。所以就剩下1,4,7,10。13。。。推測题意应该是9以内的所以就试试7咯,代码是前面代码扩展,就出结果了

__author__ = 'zhengyi'import mathfrom functools import reducedef IsPrime(x):    if x==1:        return False    k=int(math.sqrt(x))+1    for i in range(2,k):        if x%i==0:            return False    return Truedef reducefunc(x,y):    return 10*x+ydef func1(x):    i=1    val=1    while val
position: result.append(clst[-count]) del clst[-count] count-=1 result.append(clst[-position+delta]) del clst[-position+delta] count-=1 else: delta=lst[i][0]-1 position=lst[i][1]+1 while count>position: result.append(clst[-count]) del clst[-count] count-=1 result.append(clst[-position+delta]) del clst[-position+delta] count-=1 while count>0: result.append(clst[-1]) del clst[-1] count-=1 return resultcharlist=[i for i in range(7,0,-1)]k=0while True: k+=1 temp=func3(k,charlist.copy()) data=reduce(reducefunc,temp) if IsPrime(data): print(data) breakprint("Get it")

转载地址:http://xiasl.baihongyu.com/

你可能感兴趣的文章
docker常用命令
查看>>
vlan与交换机端口模式Access,Hybrid,Trunk
查看>>
Skyline开发3-没有注册类0x80040154
查看>>
CentOS6.5 添加开机自启动脚本
查看>>
使用 Python SimpleHTTPServer 快速共享文件
查看>>
Google SEO信息年终总结
查看>>
Windows不能用鼠标双击运行jar文件怎么办?
查看>>
数据库中IN和EXISTS的区别
查看>>
3.11 程序改错
查看>>
Python基本数据类型详细介绍(转)
查看>>
自动调整linux系统时间和时区与Internet时间同步
查看>>
Spring Boot启动流程详解(一)
查看>>
接口数据一致性校验工具
查看>>
快马和慢马
查看>>
vs中快捷键“转到定义(F12)”后再转回
查看>>
抽象工厂之更换皮肤
查看>>
在WPF的WebBrowser控件中抑制脚本错误
查看>>
C#性能优化:延迟初始化Lazy<T>
查看>>
设计模式笔记——设计模式原则总结
查看>>
浏览器解析html全过程详解
查看>>