本原毕达哥拉斯三元组是由三个正整数x,y,z组成,且gcd(x,y,z)=1,x*x+y*y=z*z

对于所有的本原毕达哥拉斯三元组(a,b,c) (a*a+b*b=c*c,a与b必定奇偶互异,且c为奇数。这里我们设b为偶数)

则:和

a=st

b=(s*s-t*t)/2

c=(s*s+t*t)/2

其中s>t>=1且gcd(s,t)=1

是一一对应的。

看看别人得证明:

http://blog.csdn.net/loinus/article/details/7824841

看看我的证明

有了这个定理就这题就很好做了。

Fermat vs. Pythagoras
Time Limit: 2000MS   Memory Limit: 10000K
Total Submissions: 1456   Accepted: 848

Description

Computer generated and assisted proofs and verification occupy a small niche in the realm of Computer Science. The first proof of the four-color problem was completed with the assistance of a computer program and current efforts in verification have succeeded in verifying the translation of high-level code down to the chip level. 
This problem deals with computing quantities relating to part of Fermat's Last Theorem: that there are no integer solutions of a^n + b^n = c^n for n > 2. 
Given a positive integer N, you are to write a program that computes two quantities regarding the solution of x^2 + y^2 = z^2, where x, y, and z are constrained to be positive integers less than or equal to N. You are to compute the number of triples (x,y,z) such that x < y < z, and they are relatively prime, i.e., have no common divisor larger than 1. You are also to compute the number of values 0 < p <= N such that p is not part of any triple (not just relatively prime triples). 

Input

The input consists of a sequence of positive integers, one per line. Each integer in the input file will be less than or equal to 1,000,000. Input is terminated by end-of-file

Output

For each integer N in the input file print two integers separated by a space. The first integer is the number of relatively prime triples (such that each component of the triple is <=N). The second number is the number of positive integers <=N that are not part of any triple whose components are all <=N. There should be one output line for each input line.

Sample Input

10
25
100

Sample Output

1 4
4 9
16 27
//
// main.cpp
// poj1305
//
// Created by 陈加寿 on 15/11/30.
// Copyright (c) 2015年 陈加寿. All rights reserved.
// #include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std; int mark[]; long long gcd(long long a,long long b)
{
if(b==) return a;
return gcd(b,a%b);
} int main(int argc, const char * argv[]) {
int n;
while(cin>>n)
{
memset(mark,,sizeof(mark));
int cnt=;
for(long long i=;;i+=)
{
long long a,b,c;
if( (i*i+(i+)*(i+))/ >n ) break; for(long long j=i+;;j+=)
{
if(gcd(i,j)==)
{
c=(i*i+j*j)/;
b=(j*j-i*i)/;
a=i*j;
if(c>n) break;
cnt++;
for(long long k=;k*c<=n;k++)
{
mark[a*k]=;
mark[b*k]=;
mark[c*k]=;
}
}
}
}
int ans=;
for(int i=;i<=n;i++)
if(mark[i]==) ans++;
cout<<cnt<<" "<<ans<<endl;
}
return ;
}

毕达哥拉斯三元组(勾股数组)poj1305的更多相关文章

  1. Fermat vs. Pythagoras POJ - 1305 (数论之勾股数组(毕达哥拉斯三元组))

    题意:(a, b, c)为a2+b2=c2的一个解,那么求gcd(a, b, c)=1的组数,并且a<b<c<=n,和不为解中所含数字的个数,比如在n等于10时,为1, 2, 7,9 ...

  2. 勾股数组及其应用uva106

    勾股数组 设三元组(a,b,c)满足a^2 + b^2 = c^2的勾股数组,那么是否存在无穷多个勾股数组呢, 答案是肯定的,将三元组乘以d,可以得到新的三元组(da,db,dc) 即(da)^2 + ...

  3. URAL 2032 - Conspiracy Theory and Rebranding【本源勾股数组】

    [题意] 给出三角形的三个边长,均是10^7以内的整数,问三角形的三个角的坐标是否能均是整数,输出其中任意一个解. [题解] 一开始想的是枚举一条边的横坐标,然后通过勾股定理以及算角度求出其他点的坐标 ...

  4. Python练习题 037:Project Euler 009:毕达哥拉斯三元组之乘积

    本题来自 Project Euler 第9题:https://projecteuler.net/problem=9 # Project Euler: Problem 9: Special Pythag ...

  5. POJ 1305 Fermat vs. Pythagoras (毕达哥拉斯三元组)

    设不定方程:x^2+y^2=z^2若正整数三元组(x,y,z)满足上述方程,则称为毕达哥拉斯三元组.若gcd(x,y,z)=1,则称为本原的毕达哥拉斯三元组. 定理:正整数x,y,z构成一个本原的毕达 ...

  6. bzoj 1041: [HAOI2008]圆上的整点 本原勾股數組

    1041: [HAOI2008]圆上的整点 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2027  Solved: 853[Submit][Stat ...

  7. FZU1669 Right-angled Triangle【毕达哥拉斯三元组】

    主题链接: pid=1669">http://acm.fzu.edu.cn/problem.php?pid=1669 题目大意: 求满足以a.b为直角边,c为斜边,而且满足a + b ...

  8. hdu 3939(勾股+容斥)

    题意: 给定一个整数L(L<=1e12),计算(x,y,z)组的个数.其中x<y<z,x^2+y^2=z^2,gcd(x,y)==1,gcd(x,z)==1,gcd(y,z)==1. ...

  9. 欧拉计划之题目9:找出唯一的满足a + b + c = 1000的毕达哥拉斯三元组{a, b, c}

    本题来自:http://pe.spiritzhang.com/index.php/2011-05-11-09-44-54/10-9a--b--c--1000a-b-c #include <std ...

随机推荐

  1. ISP模块之RAW DATA去噪(二)--BM3D算法

    在正式开始本篇文章之前,让我们一起回顾一下CFA图像去噪的一些基本思路与方法.接着我会详细地和大家分享自己学习理解的BM3D算法,操作过程,它的优缺点,最后会给出算法效果图供参考. 在ISP模块里,研 ...

  2. tensorflow BasicRNNCell调试

    运行以下代码,进入~/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/rnn.py和~/anaconda3/lib/python ...

  3. Elasticsearch安装(四), elasticsearch head 插件安装和使用。

    安装方式如下: 一.安装Elasticsearch-Head 1.插件安装方式(推荐) #在Elasticsearch目录下 $/bin/plugin -install mobz/elasticsea ...

  4. .net平台 基于 XMPP协议的即时消息服务端简单实现

    .net平台 基于 XMPP协议的即时消息服务端简单实现 昨天抽空学习了一下XMPP,在网上找了好久,中文的资料太少了所以做这个简单的例子,今天才完成.公司也正在准备开发基于XMPP协议的即时通讯工具 ...

  5. SpringMVC文件上传的配置

    记述一下步骤以备查. 准备工作: 需要把Jakarta Commons FileUpload及Jakarta Commons io的包放lib里. 我这边的包是: commons-fileupload ...

  6. 怎么运行Typescript

    依据官方示例: npm i -g typescript 示例:tsc *.ts 实例:tsc hello.ts 不过以上实现的太有限制了,如下实现可满足正常测试以及学习使用 package,json ...

  7. Layer 初始

    Layer 初始 介绍:很不错的一个弹出框解决方案 丰富多样的Web弹出层组件,可轻松实现Alert/Confirm/Prompt/普通提示/页面区块/iframe/tips等等几乎所有的弹出交互.目 ...

  8. Roboware 下打包成so 文件并引用

      一.生成.so文件 在ros中编译.so文件,如同在vs中编译C++版的dll文件.具体步骤如下: 步骤1: 首先建立.h文件和一个.cpp文件(该.cpp文件就是此次封装的内容)   步骤2: ...

  9. 压力测试衡量CPU的三个指标:CPU Utilization、Load Average和Context Switch Rate

    分类: 4.软件设计/架构/测试 2010-01-12 19:58 34241人阅读 评论(4) 收藏 举报 测试loadrunnerlinux服务器firebugthread 上篇讲如何用LoadR ...

  10. 在 Linux 系统下使用 PhotoRec & TestDisk 工具来恢复文件

    当你在系统中有意或无意地使用 shift + delete 组合键.删除选项,或是清空回收站的方式来删除一个文件时,该文件的内容并没有从硬盘(或是其它存储设备)上直接销毁. 它仅仅是从系统的目录结构中 ...