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] 注意 ...
随机推荐
- WPF中的动画——(五)关键帧动画
与 From/To/By 动画类似,关键帧动画以也可以以动画形式显示目标属性值. 和From/To/By 动画不同的是, From/To/By 动画只能控制在两个状态之间变化,而关键帧动画则可以在多个 ...
- volitale最经典理解
volatile跟Java的内存模型有关,非volatile变量时,平常情况,线程执行时会将变量从主内存加载到线程工作内存,建立一个副本,在某个时刻写回. valatile指的每次都读取主内存的值,有 ...
- Tomcat监控—Status页面
原文:http://jingyan.baidu.com/article/925f8cb8f3d925c0dce05677.html 修改配置文件tomcat-users(该文件在Tomcat安装程序根 ...
- Linq 时间参数的一个坑
背景:查询某个字段大于系统时间的数据 两种写法: 1.DataTime now=DateTime.Now; var result=dbContext.Table1.Created>now 2. ...
- RES协议
MFC 通过HTML访问内部资源 资源导入JPG的图片,资源对应ID是137 <img src="res:/JPG/#137" width="100%" ...
- [Linux Memory] 用/proc/stat计算cpu的占用率
转载自:http://blog.csdn.net/pppjob/article/details/4060336 在Linux下,CPU利用率分为用户态,系统态和空闲态,分别表示CPU处于用户态执行的时 ...
- 二、ELKStack集群架构设计
一.ELKStack介绍与入门实践 二.Elasticsearch 集群架构图 服务器配置:Centos6.6 x86_64 CPU:1核心 MEM:2G (做实验,配置比较低一些) 注:这里配置el ...
- 【Linux】apt-get install 怎么阻止弹出框,使用脚本默认自动安装?
You can do a couple of things for avoiding this. Setting the DEBIAN_FRONTEND variable to noninteract ...
- [Android Pro] 注册 Google Play 开发者帐户
官网地址: https://support.google.com/googleplay/android-developer/answer/6112435?hl=zh-Hans 博客地址: http:/ ...
- [React + Functional Programming ADT] Connect State ADT Based Redux Actions to a React Application
With our Redux implementation lousy with State ADT based reducers, it is time to hook it all up to a ...