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 ...
随机推荐
- Flume NG基本架构与Flume NG核心概念
导读 Flume NG是一个分布式.可靠.可用的系统,它能够将不同数据源的海量日志数据进行高效收集.聚合.移动,最后存储到一个中心化数据存储系统中. 由原来的Flume OG到现在的Flume NG, ...
- Lua相关回调总结【转】
原文 http://www.zaojiahua.com/lua-callback-functions.html 最近做一个小项目,是用Lua写的,中间用到了很多的回调,基本Cocos中的那几种常用回调 ...
- Unity相机平滑跟随
简介 unity中经常会用到固定视角的相机跟随,然后百度发现大家都是自己写的,然后偶也写咯一个,分享一下 PS: 由于刚学C#不久,才发现delegate这个东东,也不知道对性能影响大不大,但是看MS ...
- 跨服务器进行SQL Server数据库的数据处理
exec sp_addlinkedserver 'ITDB', ' ', 'SQLOLEDB', '服务器IP' exec sp_addlinkedsrvlogin 'ITDB', 'false ', ...
- 慕课网中网页定位导航中js相关问题总结
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...
- android学习之路资料集合
版权声明:本文为 stormzhang 原创文章,可以随意转载,但必须在明确位置注明出处!!! 这篇博客背后的故事 一路走来很不容易,刚好知乎上被人邀请回答如何自学android编程, 就借这个机会在 ...
- SQL基本操作——事务
事务是并发和恢复控制的基本单元. 事务四个属性:原子性.一致性.隔离性.持久性. 原子性:一个事务是一个不可分割的单位,事务中包括的诸多操作要么成功要么都失败. 一致性:事务必须使数据库从一个一致性状 ...
- swift class protocol-限定协议只能由类实现
protocol GameMode:class “You can limit protocol adoption to class types (and not structures or enume ...
- centOS7创建python虚拟环境
参考: 非常棒的2篇博客 https://www.centos.bz/2018/05/centos-7-4-%E5%AE%89%E8%A3%85python3%E5%8F%8A%E8%99%9A%E6 ...
- CAD绘制一个直径标注(com接口VB语言)
主要用到函数说明: _DMxDrawX::DrawDimDiametric 绘制一个直径标注.详细说明如下: 参数 说明 DOUBLE dChordPointX 在被标注的曲线上的第一个点X值 DOU ...