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 ...
随机推荐
- nutz中实现登录验证
一.nutz是什么 nutz是一个轻便的web端开发框架.主页如下:http://www.nutzam.com/core/nutz_preface.html 二.session简单介绍 大家都知道ht ...
- Linux查看 kennel , 物理CPU个数、核数、逻辑CPU个数
other article on my list: 查看进程 https://i.cnblogs.com/PostDone.aspx?postid=9231604&actiontip=%E4% ...
- sqldependency类轮询功能
System.Data.SqlClient.SqlDependency类为我们提供了一个关于sql2005的很好的功能 ,虽然这个东西限制有很多很多,但还是有很实用价值的. 我们先看一个演示例子: 例 ...
- [Cypress] Get started with Cypress
Adding Cypress to a project is a simple npm install away. We won’t need any global dependencies beyo ...
- Android Studio左边栏Project不见了?
非常多Android Stuio刚開始学习的人可能会一不小心把左边的Project栏给关了.结果发现找非常久也没找到怎么再打开Project栏. 如图.点击左下角button,Project就出来了.
- PHP统计所有字符在字符串中出现的次数
<?php //统计字符串中出现的字符,出现次数 echo '<pre>'; $str = 'aaabbccqqwweedfghhjffffffffggggggggg';//字符串示 ...
- Window上python 开发--1.搭建开发环境
事实上在开发python最好在ubuntu环境下,简单也便于扩展各个package.可是我的linux的电脑临时不在身边.还的我老婆的电脑win7没办法啊. 因为python的跨平台性.在window ...
- hdoj--1083--Courses(最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- nginx配置访问密码,让用户输入用户名密码才能访问
如果我们在 nginx 下搭建了一些站点,但是由于站点内容或者流量的关系,我们并不想让所有人都能正常访问,那么我们可以设置访问认证.只有让用户输入正确的用户名和密码才能正常访问.效果如下: 在 ngi ...
- Ubuntu搭建docker环境
一丶自己搭建Ubuntu的虚拟机(网上很多教程) PS:下带图形化界面的Ubuntu镜像,这里只说一下要装那些工具和做那些配置 安装vim sudo apt-get install ...