hdu6441 Find Integer 求勾股数 费马大定理
题目大意:
给出a和n,求满足的b和c。
思路:
数论题目,没什么好说的。
根据费马大定理,当n>2时不存在正整数解。
当n=0或者1时特判一下就可以了,也就是此时变成了一个求勾股数的问题。
勾股数的规律
1. 直角三角形短直角边为奇数,另一条直角边与斜边是两个连续自然数,则两边之和是短直角边的平方。
a=2*n+1,b=2*n*(n+1),c=2*n*(n+1)+1。例如,(3、4、5),(5、12、13),(7、24、25)、(9、40、41)
2. 大于2的任意偶数2n(n>1) ,都可构成一组勾股数,
三边分别是:a=2*n、b=n^2-1、c=n^2+1。(6、8、10),(8、15、17),(10、24、26)。
3. a=m^2-n^ 2, b=2*m*n,c=m^2+n^2 (其中正整数m >n >0)。
4. 如果要得到一组互质的勾股数,则可以用以下规律计算:a=4n,b=4n^2-1,c=4n^2+1(n为正整数)
?
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#define CLR(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
inline int rd(void) {
int x=0;
int f=1;
char s=getchar();
while(s<'0'||s>'9') {
if(s=='-')f=-1;
s=getchar();
}
while(s>='0'&&s<='9') {
x=x*10+s-'0';
s=getchar();
}
x*=f;
return x;
}
int main() {
int T;
ll n,a;
cin>>T;
while(T--) {
scanf("%lld%lld",&n,&a);
if(n>2||n==0) {
printf("-1 -1\n");
} else if(n==1) {
printf("%lld %lld\n",1,a+1);
} else {
if(a<=2) {
printf("-1 -1\n");
} else if(a%2==1) {
ll nn=(a-1)/2;
printf("%lld %lld\n",2*nn*(nn+1),2*nn*(nn+1)+1);
} else {
ll nn=a/2;
printf("%lld %lld\n",nn*nn-1,nn*nn+1);
}
}
}
}
?
Find Integer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 681 Accepted Submission(s): 78
Special Judge
Problem Description
people in USSS love math very much, and there is a famous math problem .
give you two integers n,a,you are required to find 2 integers b,c such that an+bn=cn.
Input
one line contains one integer T;(1≤T≤1000000)
next T lines contains two integers n,a;(0≤n≤1000,000,000,3≤a≤40000)
Output
print two integers b,c if b,c exits;(1≤b,c≤1000,000,000);
else print two integers -1 -1 instead.
Sample Input
1 2 3
Sample Output
4 5
Source
hdu6441 Find Integer 求勾股数 费马大定理的更多相关文章
- 【2018 CCPC网络赛 1004】Find Integer(勾股数+费马大定理)
Problem Description people in USSS love math very much, and there is a famous math problem . give yo ...
- 数学--数论--Find Integer(勾股数定理)
Problem Description people in USSS love math very much, and there is a famous math problem give you ...
- 2018中国大学生程序设计竞赛 - 网络选拔赛 4 - Find Integer 【费马大定理+构造勾股数】
Find Integer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- hdu 6441 Find Integer(费马大定理+勾股数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441(本题来源于2018年中国大学生程序设计竞赛网络选拔赛) 题意:输入n和a,求满足等式a^n+b^ ...
- hdu 6441 (费马大定理+勾股数 数学)
题意是给定 n 和 a,问是否存在正整数 b,c 满足:a^n + b^n == c^n.输出 b c,若不存在满足条件的 b,c,输出 -1 -1. 当 n > 2 时,由费马大定理,不存在 ...
- HDU 6441 费马大定理+勾股数
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se ...
- Project Euler 39 Integer right triangles( 素勾股数 )
题意:若三边长 { a , b , c } 均为整数的直角三角形周长为 p ,当 p = 120 时,恰好存在三个不同的解:{ 20 , 48 , 52 } , { 24 , 45 , 51 } , ...
- 笔试题-求小于等于N的数中有多少组素勾股数
题目描述: 一组勾股数满足:a2+b2=c2: 素勾股数:a,b,c彼此互质. 输入正整数N: 输出小于等于N的数中有多少组勾股数. 例: 输入:10 输出:1 思路:我是直接暴力破解的…… 首先找出 ...
- C语言 · 勾股数
勾股数 勾股定理,西方称为毕达哥拉斯定理,它所对应的三角形现在称为:直角三角形. 已知直角三角形的斜边是某个整数,并且要求另外两条边也必须是整数. 求满足这个条件的不同直角三角形的个数. [数据格式] ...
随机推荐
- 4-EasyNetQ之Logging(黄亮翻译)
EasyNetQ提供了一个Logger接口 IEasyNetQLogger: public interface IEasyNetQLogger { void DebugWrite(string for ...
- volatile关键字在多线程中的作用
- day70-oracle 12-触发器
查询是没有触发器的.trigger是一个数据库的对象.PL/SQL程序是在我插入之前执行还是在插入之后执行?触发器类似于java中的监听器. 监听插入操作,执行一段PLSQL程序. 禁止在非工作时间插 ...
- elasticsearch2.x ik插件
先来一个标准分词(standard),配置如下: curl -XPUT localhost:/local -d '{ "settings" : { "analysis&q ...
- [poj3348]Cows
题目大意:求凸包面积. 解题关键:模板题,叉积求面积. 这里的cmp函数需要调试一下,虽然也对,与普通的思考方式不同. #include<cstdio> #include<cstri ...
- 使用Post进行Http通信
--------------siwuxie095 有道翻译官网:http://fanyi.youdao.com/ 找到官网页面下方的 有 ...
- Group Layout
----------------siwuxie095 将根面板 contentPane 的布局切换为 Group Layout Grou ...
- 关于Java中hashCode方法的实现源码
首先来看一下String中hashCode方法的实现源码. public int hashCode() { int h = hash; if (h == 0 && value.leng ...
- 初识Servlet(JSP)
Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层. Servle ...
- VMWare虚拟机无法打开内核设备"\\.\Global\vmx86"的解决方法
cmd执行: 1.net start vmci 2.net start vmx86 3.net start VMnetuserif