Project Euler 33 Digit cancelling fractions
题意: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的更多相关文章
- Project Euler:Problem 33 Digit cancelling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- Project Euler 34 Digit factorials
题意:判断一个数 N 的各个位数阶乘之和是否为其本身,找出所有符合要求的数然后求和 思路:此题思路跟 30 题相同,找到枚举上界 10 ^ n <= 9! × n ,符合要求的 n < 6 ...
- Project Euler 30 Digit fifth powers
题意:判断一个数 N 的每一位的5次方的和是否为其本身 ,求出所有满足条件的数的和 思路:首先设这个数 N 为 n 位,可以简单的判断一下这个问题的上界 10 ^ n <= 9 ^ 5 × n, ...
- (Problem 33)Digit canceling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- Python练习题 047:Project Euler 020:阶乘结果各数字之和
本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...
- Python练习题 044:Project Euler 016:乘方结果各个数值之和
本题来自 Project Euler 第16题:https://projecteuler.net/problem=16 ''' Project Euler 16: Power digit sum 2* ...
- Python练习题 039:Project Euler 011:网格中4个数字的最大乘积
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
随机推荐
- Android获取设备屏幕宽高像素值的两个方法
private void get1() { Resources resources = this.getResources(); DisplayMetrics dm = resources.getDi ...
- structs实现三种action的方法
第一种:一般类,带有public String execute()方法. 另外一种:继承LoginActionInterface implements Action接口的类. 第三种:继承LoginA ...
- Java设计模式菜鸟系列(十五)建造者模式建模与实现
转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/39863125 建造者模式(Builder):工厂类模式提供的是创建单个类的模式.而建造者模 ...
- 支持中文的基于词为基本粒度的前缀树(prefix trie)python实现
Trie树,也叫字典树.前缀树.可用于"predictive text"和"autocompletion".亦可用于统计词频(边插入Trie树边更新或加入词频) ...
- Codeforces Round #256 (Div. 2) B
B. Suffix Structures Bizon the Champion isn't just a bison. He also is a favorite of the "Bizon ...
- Mac下搭建hexo3.0博客
Mac下搭建hexo3.0博客(文章同步自个人博客站点以及Github博客https://xingstarx.github.io/) window环境下搭建hexo博客 详细内容能够參考这一篇文章怎样 ...
- 驱动开发(8)处理设备I/O控制函数DeviceIoControl
本博文由CSDN博主zuishikonghuan所作,版权归zuishikonghuan全部,转载请注明出处:http://blog.csdn.net/zuishikonghuan/article/d ...
- Spring+EhCache缓存实例(具体解说+源代码下载)
一.ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架,具有高速.精干等特点,是Hibernate中默认的CacheProvider.Ehcache是一种广泛使用的开源Java分布式 ...
- linux下udev简介【转】
本文转载自:http://blog.csdn.net/skyflying2012/article/details/9364555 一.关于Udev u即user space,dev是device,通过 ...
- 最全三大框架整合(使用映射)——applicationContext.xml里面的配置
applicationContext.xml: <?xml version="1.0" encoding="UTF-8"?> <beans x ...