(Problem 33)Digit canceling fractions
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.
题目大意:
分数 49/98 是一个奇怪的分数:当一个菜鸟数学家试图对其进行简化时,他可能会错误地可以认为通过将分子和分母上的9同时去除得到 49/98 = 4/8。但他得到的结果却是正确的。
我们将30/50 = 3/5这样的分数作为普通个例。
一共有四个这样的非普通分数,其值小于1,并且包括分子和分母都包括2位数。 如果将这四个分数的乘积约分到最简式,分母是多少?
//(Problem 33)Digit canceling fractions
// Completed on Thu, 25 Jul 2013, 17:47
// Language: C
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/
#include<stdio.h>
void swap(int *a, int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
} int gcd(int a, int b)
{
int r;
if (a < b)
swap(&a,&b);
if (!b)
return a;
while ((r = a % b) != ) {
a = b;
b = r;
}
return b;
} void find()
{
int i;
int M,N;
M=N=;
for(i=; i<; i++)
{
for(int j=i+; j<; j++)
{
int t=gcd(i,j);
if(t== || i/t> || j/t> || i%!=j/)
continue;
else
{
int a=i/,b=j%;
if(a/gcd(a,b)==i/t && b/gcd(a,b)==j/t)
{
M*=i/t;
N*=j/t;
}
}
}
}
printf("%d\n",N/gcd(M,N));
} int main()
{
find();
return ;
}
Answer:
|
100 |
(Problem 33)Digit canceling fractions的更多相关文章
- (Problem 74)Digit factorial chains
The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...
- (Problem 34)Digit factorials
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are ...
- (Problem 73)Counting fractions in a range
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- (Problem 72)Counting fractions
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- (Problem 16)Power digit sum
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of th ...
- (Problem 46)Goldbach's other conjecture
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...
- (Problem 29)Distinct powers
Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
随机推荐
- Summer Holiday(强联通入度最小点)
Summer Holiday Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 为客户打造RAC-DG一些遇到的问题汇总
昨日有建立一个客户RAC-DG物理备用数据库,这里的一般过程中再次列举一下,为了不涉及泄露隐私.的主要参数已被替换名称.详细路径也不一致.因为环境的客户端不与本机连接的网络同意,当故障不能削减各种报警 ...
- Visual format language
所谓的VFL语言其实就是Visual format language 的缩写,是一种使用代码添加约束的方式,类似于Masonry SDAutolayout的效果,但是操作起来可能要相对简单.一行代码 ...
- 关于php支持的协议与封装协议
<?php /* * php://stdin 标准输入流 * php://stdout 标准输入流 * php://stderr 标准错误流 * php://output 只写的数据流 * ph ...
- Linux 下 Hadoop java api 问题
1. org.apache.hadoop.security.AccessControlException: Permission denied: user=opsuser, access=WRITE, ...
- jquery回调函数callback的使用
回调函数必须是全局函数或者静态函数,不可定义为某个特定的类的成员函数 callback函数在当前动画100%完成之后执行 $("p").hide(1000); alert(&quo ...
- ThinkPHP第十五天(setField、setInc、setDec、关联模型)
1.ThinkPHP中的比较特殊连贯操作 如果要更新某个字段可以用setField方法,比如M('user')->where('id=1')->setField('username','T ...
- CDOJ 1259 昊昊爱运动 II bitset+线段树
题目链接 昊昊喜欢运动 他N天内会参加M种运动(每种运动用一个[1,m]的整数表示) 现在有Q个操作,操作描述如下 昊昊把第l天到第r天的运动全部换成了x(x∈[1,m]) 问昊昊第l天到第r天参加了 ...
- 12-C语言字符串
目录: 一.字符串 二.字符串输入输出函数 三.指针数组(字符串数组) 回到顶部 一.字符串 1 一组字符数组,以数组的首地址开始,以ASC码的'\0'结束. 2 字符串与普通数组的区别:普通数组没有 ...
- 【转】IOS 输入框被键盘遮盖的解决方法
做IOS开发时,难免会遇到输入框被键盘遮掩的问题.上网上搜索了很多相关的解决方案,看了很多,但是由衷的觉得太麻烦了. 有的解决方案是将视图上的所有的东西都添加到一个滚动视图对象( UIScrollVi ...