EularProject 32: 数字1-9排列构成乘法等式
Pandigital products
Problem 32
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, the 5-digit number, 15234, is 1 through 5 pandigital.
The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.
Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.
Answer:
45228
Completed on Sat, 25 Jul 2015, 15:13
python code:
from math import sqrt
def func(x):
s0=set(str(x))
for i in range(2,min(100,int(sqrt(x)+1))):
if x%i==0:
s1=set(str(i))
s2=set(str(x//i))
s=s0|s1|s2
if len(s)==9 and '0' not in s:
return True
return False
result=0
for i in range(1000,9999):
Pstr=str(i)
if len(set(Pstr))==4 and '0' not in Pstr:
if func(i):
result+=i
print(i)
print(result)
这里由于要求乘积不能反复,能够考虑对乘积候选项循环推断,把满足条件的加起来,而且非常easy反证证明乘积项数字位数仅仅能为4。
数字1-9是一个有趣的问题,很多其它问题能够參考
http://www.worldofnumbers.com/ninedig1.htm
EularProject 32: 数字1-9排列构成乘法等式的更多相关文章
- 洛谷3176 [HAOI2015]数字串拆分 (矩阵乘法+dp)
qwq真的是一道好题qwq自己做基本是必不可能做出来的. 首先,如果这个题目只是求一个\(f\)数组的话,那就是一道裸题. 首先,根据样例 根据题目描述,我们能发现其实同样数字的不同排列,也是属于不同 ...
- 【BZOJ】3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛(排列组合+乘法逆元+欧拉定理/费马小定理)
http://www.lydsy.com/JudgeOnline/problem.php?id=3398 以下牡牛为a,牝牛为b. 学完排列计数后试着来写这题,“至少”一词可以给我们提示,我们可以枚举 ...
- 剑指Offer面试题:32.数字在排序数组中出现的次数
一.题目:数字在排序数组中出现的次数 题目:统计一个数字在排序数组中出现的次数.例如输入排序数组{1,2,3,3,3,3,4,5}和数字3,由于3在这个数组中出现了4次,因此输出4. 二.解题思路 2 ...
- 1到32 数字正则 还有IP的
正则是按位解析匹配的,所以[1-32]是不行的. 解析: 1.1-32,包含1位数(1-9)和2位数(10-32) 2.10-32必须切割,10-19和20-29形式一样,得到[12][0-9],30 ...
- Python进阶之路---1.4python数据类型-数字
python入门基础 声明:以后python代码未注明情况下,默认使用python3.x版本 1.python代码基础:print print('hello,python') 1.1pyt ...
- 使用opencv调用24*24点阵字库和8*16ASCII字库在图片显示文字数字
课程实验:编程读汉字点阵字库,把自己的名字和学号叠加到图片的右下位置. 主要步骤分为三部分 第一部分:读取图片(文件读取) 第二部分:读取文字并从字库中提取相应的编码(字库的存储原理) 第三部分:将相 ...
- Leetcode题库——31.下一个排列
@author: ZZQ @software: PyCharm @file: nextPermutation.py @time: 2018/11/12 15:32 要求: 实现获取下一个排列的函数,算 ...
- [CareerCup] 18.6 Smallest One Million Numbers 最小的一百万个数字
18.6 Describe an algorithm to find the smallest one million numbers in one billion numbers. Assume t ...
- lintcode:previous permutation上一个排列
题目 上一个排列 给定一个整数数组来表示排列,找出其上一个排列. 样例 给出排列[1,3,2,3],其上一个排列是[1,2,3,3] 给出排列[1,2,3,4],其上一个排列是[4,3,2,1] 注意 ...
随机推荐
- Oracle Linux logoOracle Linux
http://www.oschina.net/p/oracle_enterprise_linux
- __dopostback的用法
转载:http://blog.csdn.net/fwj380891124/article/details/8819926 在.NET中,所有的服务器控件提交到服务器的时候,都会调用__doPostBa ...
- 【shiro】报错: If the controller requires proxying (e.g. due to @Transactional), please use class-based proxying.
spring整合shiro,项目报如下错误: ==============异常开始============= java.lang.IllegalStateException: The mapped c ...
- java >>> 和 >>>=的区别
java >> 和 >>> 以及 >>>= 的区别 可能大家都知道java中>> 和 >>> 的区别,那这里我也啰嗦一下, ...
- 关于Android架构那些事
刚开始,因为业务比较赶,我们也没有进行比较好的顶层设计,对代码的要求也是最低要求——完成功能开发就行了.这种短期设计也就造成了我们代码的扩展性几乎为零,稍微添加一点新功能,都要大动干戈.在后台系统架构 ...
- python tkinter 框架开发的收费音乐免费下载工具
使用介绍: 工具下载地址:https://wps-oss.oss-cn-shenzhen.aliyuncs.com/Music2.exe 技术交流和赞助请前往我的咸鱼: https://market. ...
- SQL Server 更新 触发器
- 复制代码 代码如下: create trigger TR_MasterTable_Update on MasterTable after update as if update ([Type])- ...
- iOS:菜单控制器和菜单项:UIMenuController和UIMenuItem
菜单控制器和菜单项:弹出自定义的菜单栏窗口 提示: 1. Menu所处的View必须实现 – (BOOL)canBecomeFirstResponder, 且返回YES2. Menu所处的View必须 ...
- Linux编程中的坑——C++中exit和return的区别
今天遇到一个坑,折腾了一天才把这个坑填上,情况是这样的: 写了段代码,在main()函数中创建一个分离线程,结果这个线程什么都没干就直接挂掉了,代码长这样: int main() { 创建一个分离线程 ...
- acle联机日志文件的维护
1.刷新重做日志缓存的时机 a.commit b.缓存满了 c.checkpoint,checkpoint的触发有两种机制: 定时触发,由log_checkpoint_interval[1]参数决定间 ...