(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 ...
随机推荐
- HDU 3613 Best Reward(扩展KMP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3613 [题目大意] 一个字符串的价值定义为,当它是一个回文串的时候,价值为每个字符的价值的和,如果 ...
- UVA1291----Dance Dance Revolution----3维DP
本文出自:http://blog.csdn.net/dr5459 题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&a ...
- IE 中开发,兼容与性能测试工具汇总
前言 对于开发者来说, IE的兼容性是最让人头疼的. 因为是微软的产品, 且绑定在操作系统上, 所以IE的占用率还是相当大, 对于开发者来说, 这部分的兼容的考虑就不可避免了. 对于IE 的各版本来说 ...
- request.getParameterValues与request.getParameter的差别
一. 简单的对照 request.getParameter用的比較多,相对熟悉 request.getParameterValues(String name)是获得如checkbox类(名字同样, ...
- 简单的web三层架构系统【第一版】
SQLhelper助手类编写: 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using Sys ...
- HDU Tickets(简单的dp递推)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- mysql修改用户名和密码
修改用户名 mysql> use mysql; 选择数据库Database changedmysql> update user set user="dns" wher ...
- Oracle "Job定时"
今天需要做个定时器,定时到别的库导入数据用到了Job,第一次使用记录下来,如果有第一次操作的可以借鉴一下 1.首先,使用Toad新建job,进入配置页面
- night Mode 夜间模式css
*,*:before,*:after,html[mode='nightmode'] * { color: #61615f !important; border-color: #212a32 !impo ...
- css为网页顶部和底部都加入背景图
网页背景图是我们常用的功能,一般来说.给网页加一个背景图,只要在网页的body标签中加入css属性就行. 代码如下:<body style="background-image:url( ...