Digit cancelling fractions
2016-04-24 21:54
288 查看
Digit cancelling fractions
Problem 33
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.
If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
考虑的比较简单,可消去的数字只有1-9共9个,另外的数字,组合方案总共9*9个,每一个组合,有4中匹配,遍历一下即可.
def DigitCancellingFractions():
result = set()
for i in range(1,10):
for j in range(1,10):
for k in range(1,10):
tmp1 = i * 10 + j
tmp2 = i * 10 + k
tmp3 = j * 10 + i
tmp4 = k * 10 + i
if tmp1 < tmp2 and tmp1 / tmp2== j / k:
result.add((j,k))
if tmp3 < tmp2 and tmp3 / tmp2== j / k:
result.add((j,k))
if tmp1 < tmp4 and tmp1 / tmp4== j / k:
result.add((j,k))
if tmp3 < tmp4 and tmp3 / tmp4== j / k:
result.add((j,k))
print(result)
DigitCancellingFractions()
相关文章推荐
- java注解
- xcode提交版本时提示The working copy "MyPro" failed to commit files.解决方法
- BJTU 数学题
- 数值算法
- UVA_10020_Minimal coverage
- 优雅的创建一个相册管理类(兼容AssetsLibrary和PhotoKit)
- Java多线程干货系列—(一)Java多线程基础
- 站立会议第七天
- win10自带中文输入法的用户体验
- 站立会议个人博客6(2016/4/24)
- 百度移动SSP启动广告
- Linux NAPI/非NAPI 网卡驱动部分
- JAVA——包(package)及对jar包的操作
- MySql-使用事件调度器(event_scheduler)
- NJUST 1922
- bzoj 3262: 陌上花开 【cdq分治】
- 数据结构 实验三 树与二叉树的常见操作
- Razor视图中的 @helper
- 【朝花夕拾】虚拟主机克隆不能上网问题总结
- usaco回文平方数