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

思路:直接枚举判断即可,需要注意 11/22 这种类型的数


/*************************************************************************
> File Name: euler033.c
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月25日 星期日 16时44分46秒
************************************************************************/ #include <stdio.h>
#include <inttypes.h> int64_t gcd(int64_t a , int64_t b) {
return b == 0 ? a : gcd(b , a % b);
}
bool check(int64_t x , int64_t y) {
int64_t d = gcd(x , y);
if( (x % 10) == (x / 10) || (y % 10) == (y / 10) ) return false;
return (((x / d) * (y % 10)) == ((y / d) * (x / 10))) && ((x % 10) == (y / 10));
}
int32_t main() {
int64_t mol = 1 , den = 1;
for(int32_t i = 10 ; i < 99 ; i++){
for(int32_t j = i + 1 ; j <= 99 ; j++){
if( check(i , j) ) {
printf("i = %d , j = %d\n",i,j);
mol *= (int64_t)i; den *= (int64_t)j;
}
}
}
printf("%"PRId64"\n", den / gcd(mol , den));
return 0;
}

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

  1. Project Euler:Problem 33 Digit cancelling fractions

    The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...

  2. Project Euler 34 Digit factorials

    题意:判断一个数 N 的各个位数阶乘之和是否为其本身,找出所有符合要求的数然后求和 思路:此题思路跟 30 题相同,找到枚举上界 10 ^ n <= 9! × n ,符合要求的 n < 6 ...

  3. Project Euler 30 Digit fifth powers

    题意:判断一个数 N 的每一位的5次方的和是否为其本身 ,求出所有满足条件的数的和 思路:首先设这个数 N 为 n 位,可以简单的判断一下这个问题的上界 10 ^ n <= 9 ^ 5 × n, ...

  4. (Problem 33)Digit canceling fractions

    The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...

  5. Python练习题 047:Project Euler 020:阶乘结果各数字之和

    本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...

  6. Python练习题 044:Project Euler 016:乘方结果各个数值之和

    本题来自 Project Euler 第16题:https://projecteuler.net/problem=16 ''' Project Euler 16: Power digit sum 2* ...

  7. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

  8. [project euler] program 4

    上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...

  9. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

随机推荐

  1. servlet理解

    可得到一个结论:该JSP页面中的每个字符都由test1_jsp.java文件的输出流生成. 根据上面的JSP页面工作原理图,可以得到如下四个结论: — JSP文件必须在JSP服务器内运行. — JSP ...

  2. linux下Oracle11g RAC搭建(七)

    linux下Oracle11g RAC搭建(七) 六.安装Grid 启动GRID安装界面 方式一:redhat下调整分辨率 [root@node1 ~]# xhost +       //授权 [ro ...

  3. Struts简单介绍

    一.在介绍struts之前,先来了解一下什么是MVC框架吧. 1.MVC介绍 MVC全名是Model View Controller.是模型(model)-视图(view)-控制器(controlle ...

  4. 开源项目 apk cfg and android app path profiling

    暑假里面完毕的一个小项目,limitation还是挺多的. 期待未来有更大的motivation 去完好它.通过此次的项目设计,对于smali的语法更加了解了,对于进一步学习android app的安 ...

  5. 11gR2 Database Services for &quot;Policy&quot; and &quot;Administrator&quot; Managed Databases (文档 ID 1481647.1)

    In this Document   Purpose   _afrLoop=1459311711568804&id=1481647.1&displayIndex=6&_afrW ...

  6. 修改linux内核的启动logo和禁用启动光标【转】

    本文转载自:http://blog.csdn.net/hunanchenxingyu/article/details/40992947 1-1.制作logo的方法: 首先选择一个自己喜欢的图片,png ...

  7. Linux - shell壳脚本

    shell脚本. 壳,充当一个翻译,让计算机能够认识的二进制程序,并将结果翻译给我们. 加在内核上,可以跟内核打交道的壳. 可以通过/etc/shells 来查看. [root@local ~]# c ...

  8. php basic syntax

    php basic syntax PHP(Hypertext Preprocessor,超文本预处理器). 一.PHP入门 1.指令分隔符“分号”         语义分为两种:一种是在程序中使用结构 ...

  9. php 判断字符串包含中文(转)

    $str = "测试中文"; echo $str; echo "<hr>"; //if (preg_match("/^[".ch ...

  10. Django中的session和cookie及分页设置

    cookie Cookie的由来 大家都知道HTTP协议是无状态的. 无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接影响,也不 ...