Project Euler 75: Singular integer right triangles
思路:
勾股数组,又称毕达格拉斯三元组。
公式:a = s*t b = (s^2 - t^2) / 2 c = (s^2 + t^2) / 2 s > t >=1 且为互质的奇数
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head const int N = ;
int cnt[N+];
int main() {
for (LL s = ; ; s += ) {
if(s > N) break;
for (LL t = ; t < s; t += ) {
LL a = s*t, b = (s*s - t*t)/, c = (s*s + t*t)/;
if(a > N || b > N || c > N) break;
if(__gcd(s, t) > ) continue;
if(a+b+c > N) continue;
LL tot = a+b+c;
for (LL i = tot; i <= N; i += tot) cnt[i]++;
}
}
int ans = ;
for (int i = ; i <= N; ++i) if(cnt[i] == ) ans++;
cout << ans << endl;
return ;
}
Project Euler 75: Singular integer right triangles的更多相关文章
- Project Euler 75:Singular integer right triangles
题目链接 原题: It turns out that 12 cm is the smallest length of wire that can be bent to form an integer ...
- Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.
In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...
- Project Euler 第一题效率分析
Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...
- 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 ...
- Project Euler 9
题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...
- project euler 169
project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...
- 【Project Euler 8】Largest product in a series
题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...
随机推荐
- python拼接multipart/form-data类型post请求格式
# 最近要做form-data类型接口,大多数这种格式用来文件上传,但是我们公司就是用这种格式传输请求数据. # 百度了一些基本都是files方式的,可是我们需要data=方式的.下面自己来拼接,代码 ...
- JS中将json字符串转为json对象的三种方式
第一种:利用JSON的parse方法,即jsonObj=JSON.parse(jsonStr); 第二种:jsonObj = eval('(' + jsonStr+ ')'); 第三种:比较难理解:j ...
- web_app框架
web app 建立在asyncio的基础上,因此用aiohttp写一个基本的app.py import logging; logging.basicConfig(level=logging.INFO ...
- cocos2dx在win10系统上的VS2017运行时报错:丢失MSVCR110.dll
如题,运行环境为cocos2dx 3.14.1,win10系统,VS2017. 编译cocos2dx的cocos2d-x-3.14.1/build/cocos2d-Win32.sln已通过,不过运行时 ...
- git宝典—应付日常工作使用足够的指北手册
最近公司gitlab又迁移,一堆git的命令骚操作,然鹅git命令,感觉还是得复习下——其实,git现在界面操作工具蛮多,比如intellij 自带的git操作插件就不错,gitlab github ...
- 【Linux】Jenkins安装(一)
摘要 本章介绍Jenkins的简单使用,关于Jenkins的安装,参照[Linux]Jenkins安装(一) 事例说明:在linux环境下,安装的jenkins,集成svn,tomcat的环境,项目是 ...
- QQ/微信中被禁止访问的网页怎么打开
为什么关心这种技术?因为我经常听到身边搞微商.搞微信项目的朋友都在叫苦连天,由于微信域名屏蔽.微信域名被拦截.弄得他们尸横遍野,损失的连过年回家的路费都没了,曾经的叱咤风云一下变成了今日的倒亏损.腾讯 ...
- php 图片添加文字,水印
因为工作需求,用到这个,网上找了很多,也没有找到好的方式,最后找到这种感觉比较简单的方式,记录下来,以备后用. $im = imagecreatefrompng("img/yyk_bg. ...
- 语音活性检测器py-webrtcvad安装使用
谷歌为WebRTC项目开发的VAD是目前最优秀.最先进和免费的产品之一.webrtcvad是WebRTC语音活动检测器(VAD)的python接口.兼容python2和python3.功能是将一段音频 ...
- Lists.newArrayListWithExpectedSize( int estimatedSize)
Lists.newArrayListWithExpectedSize( int estimatedSize) 构造一个期望长度为estimatedSize的ArrayList实例. 源码: publ ...