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. #include <iostream>
  2. using namespace std;
  3.  
  4. int gcd(int a, int b)
  5. {
  6. while (b)
  7. {
  8. if (a < b)
  9. {
  10. int tmp = b;
  11. b = a;
  12. a = tmp;
  13. }
  14. int t = b;
  15. b = a % b;
  16. a = t;
  17. }
  18. return a;
  19. }
  20.  
  21. int main()
  22. {
  23. int fz = 1;
  24. int fm = 1;
  25. int res;
  26. for (int x = 10; x <= 98; x++)
  27. {
  28. for (int y = x + 1; y <= 99; y++)
  29. {
  30. int a = x / 10;
  31. int b = x % 10;
  32. int c = y / 10;
  33. int d = y % 10;
  34. if ((b - c) == 0 && (y*a == x*d) && (d != 0))
  35. {
  36. fz *= a;
  37. fm *= d;
  38. }
  39. }
  40. }
  41. res = fm / gcd(fz, fm);
  42. cout << res << endl;
  43. system("pause");
  44. return 0;
  45. }

Project Euler:Problem 33 Digit cancelling fractions的更多相关文章

  1. 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 ...

  2. Project Euler 33 Digit cancelling fractions

    题意:49/98是一个有趣的分数,因为可能在化简时错误地认为,等式49/98 = 4/8之所以成立,是因为在分数线上下同时抹除了9的缘故.分子分母是两位数且分子小于分母的这种有趣的分数有4个,将这四个 ...

  3. 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 ...

  4. 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 ...

  5. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. shell script练习:利用日期进行文件的创建

    随日期变化:利用 date 进行文件的创建 想像一个状况,假设我的服务器内有数据库,数据库每天的数据都不太一样,因此当我备份时, 希望将每天的数据都备份成不同的档名,这样才能够让旧的数据也能够保存下来 ...

  2. Oracle 10g RAC的负载均衡配置[转载]

    Oracle 10g RAC的负载均衡配置 负载均衡是指连接的负载均衡.RAC的负载均衡主要是指新会话连接到RAC数据库时,如何判定这个新的连接要连到哪个节点进行工作.在RAC中,负载均衡分为两种,一 ...

  3. python--11、协程

    协程,又称微线程,纤程.英文名Coroutine. 子程序,或者称为函数,在所有语言中都是层级调用,比如A调用B,B在执行过程中又调用了C,C执行完毕返回,B执行完毕返回,最后是A执行完毕. 所以子程 ...

  4. Paint、Canvas

    1.Canvas类 public class Canvas { public static final int ALL_SAVE_FLAG = 31; /** @deprecated */ @Depr ...

  5. python 之 sqlite3

    # -*- coding: utf-8 -*- ''' 创建数据库日志,三列为时间 身份证号和备注名''' import os import sys import sqlite3 import dat ...

  6. JS——delete

    1.对象属性删除 <script> function fun(){ this.name = 'mm'; } var obj = new fun(); console.log(obj.nam ...

  7. http服务器与https服务器的区别

    1.HTTPS服务器使用的是HTTPS协议,而HTTP使用的是HTTP协议. 2.HTTPS服务器需要向证书授权中心申请证书,一般免费证书很少,需要交费. 3.HTTP服务器与客户端传递的是明文数据, ...

  8. OpenGL第23-26小结

    到后面代码相对而言比较复杂了,因为没有系统的看红宝书(就跟字典一样,兴趣缺缺),很多操作的步骤比较迷糊. 23讲讲解了如何将环境纹理贴在球体.圆柱体等非矩形物体表面,从而达到一个反射周围景色的效果(恩 ...

  9. (转) Hibernate注解开发

    http://blog.csdn.net/yerenyuan_pku/article/details/70162268 Hibernate注解开发 在Hibernate中我们一般都会使用注解,这样可以 ...

  10. ubuntu下查看如何配置pycharm

    ubuntu中PyCharm的安装与卸载 https://blog.csdn.net/weixin_31484477/article/details/81133590 pycharm ModuleNo ...