Project Euler:Problem 33 Digit cancelling 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.
#include <iostream>
using namespace std; int gcd(int a, int b)
{
while (b)
{
if (a < b)
{
int tmp = b;
b = a;
a = tmp;
}
int t = b;
b = a % b;
a = t;
}
return a;
} int main()
{
int fz = 1;
int fm = 1;
int res;
for (int x = 10; x <= 98; x++)
{
for (int y = x + 1; y <= 99; y++)
{
int a = x / 10;
int b = x % 10;
int c = y / 10;
int d = y % 10;
if ((b - c) == 0 && (y*a == x*d) && (d != 0))
{
fz *= a;
fm *= d;
}
}
}
res = fm / gcd(fz, fm);
cout << res << endl;
system("pause");
return 0;
}
Project Euler:Problem 33 Digit cancelling fractions的更多相关文章
- Project Euler: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 ...
- Project Euler 33 Digit cancelling fractions
题意:49/98是一个有趣的分数,因为可能在化简时错误地认为,等式49/98 = 4/8之所以成立,是因为在分数线上下同时抹除了9的缘故.分子分母是两位数且分子小于分母的这种有趣的分数有4个,将这四个 ...
- Project Euler:Problem 63 Powerful digit counts
The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is ...
- Project Euler:Problem 87 Prime power triples
The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- Project Euler:Problem 32 Pandigital products
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- Project Euler:Problem 86 Cuboid route
A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the o ...
- Project Euler:Problem 76 Counting summations
It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...
- Project Euler:Problem 89 Roman numerals
For a number written in Roman numerals to be considered valid there are basic rules which must be fo ...
随机推荐
- [转]linux下ulimit命令详解
转自:http://blog.chinaunix.net/uid-23842323-id-2656582.html 1,说明:ulimit用于shell启动进程所占用的资源.2,类别:shell内建命 ...
- MYSQL 使用自定义表变量
mysql 用户自定义表变量,ENGINE=MyISAM DEFAULT CHARSET=gb2312; 制定编码方式,防止乱码 DROP TABLE IF EXISTS p_temp; creat ...
- 00-SQLite的SQL语法
SQLite的SQL语法 SQLite库可以解析大部分标准SQL语言.但它也省去了一些特性并且加入了一些自己的新特性.这篇文档就是试图描述那些SQLite支持/不支持的SQL语法的.查看关键字列表. ...
- JS——client
clientTop.clientLeft: clientTop:盒子的上boder clientLeft:盒子的左border clientWidth与clientHeight 1.在有DTD情况下: ...
- css学习笔记---盒模型,布局
1.外边距叠加 当一个元素出现在另一个元素上面时第一个元素的底边距与第二个元素的上边距发生叠加,元素被包含时也有可能会发生叠加(如果没有内边距和边框),如果一个空元素没有内边距和边框本身也会发生上下边 ...
- oracle 入门笔记--v$sql和v$sqlarea视图(转载)
转载于作者:dbtan 原文链接:http://www.dbtan.com/2009/12/vsql-and-vsqlarea-view.html v$sql和v$sqlarea视图: 上文提到,v$ ...
- Logstash_Apache日志采集
[root@Cagios logstash-]# cat /usr/local/logstash-/logstash_agent.conf input { file { type => &quo ...
- eclipse中代码整体左右移动的方法
1.向左:将要移动的代码选中,然后按TAB键2.向右:将要移动的代码选中,然后按shift+tab键 kettas: 2009-8-21
- JS DOM节点(当前标签和同级、父级、子级..之间的关系)
1. 通过顶层document节点获取 1) document.getElementById(elementId) //根据id获得 2) document.getElementsByNa ...
- HTML5易漏知识点锦集
本文通过对w3schoolHTML5基础教程,整理出比较常见的却又容易遗忘或者忽略的HTML5相关知识点.本文的标题顺序与w3school中的HTML5基础教程标题顺序保持一致.适合翻阅和复习. 1. ...