题目传送门

题目大意:

给出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

2018中国大学生程序设计竞赛 - 网络选拔赛

hdu6441 Find Integer 求勾股数 费马大定理的更多相关文章

  1. 【2018 CCPC网络赛 1004】Find Integer(勾股数+费马大定理)

    Problem Description people in USSS love math very much, and there is a famous math problem . give yo ...

  2. 数学--数论--Find Integer(勾股数定理)

    Problem Description people in USSS love math very much, and there is a famous math problem give you ...

  3. 2018中国大学生程序设计竞赛 - 网络选拔赛 4 - Find Integer 【费马大定理+构造勾股数】

    Find Integer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  4. hdu 6441 Find Integer(费马大定理+勾股数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441(本题来源于2018年中国大学生程序设计竞赛网络选拔赛) 题意:输入n和a,求满足等式a^n+b^ ...

  5. hdu 6441 (费马大定理+勾股数 数学)

    题意是给定 n 和 a,问是否存在正整数 b,c 满足:a^n + b^n == c^n.输出 b  c,若不存在满足条件的 b,c,输出 -1 -1. 当 n > 2 时,由费马大定理,不存在 ...

  6. HDU 6441 费马大定理+勾股数

    #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se ...

  7. Project Euler 39 Integer right triangles( 素勾股数 )

    题意:若三边长 { a , b , c } 均为整数的直角三角形周长为 p ,当 p = 120 时,恰好存在三个不同的解:{ 20 , 48 , 52 } , { 24 , 45 , 51 } , ...

  8. 笔试题-求小于等于N的数中有多少组素勾股数

    题目描述: 一组勾股数满足:a2+b2=c2: 素勾股数:a,b,c彼此互质. 输入正整数N: 输出小于等于N的数中有多少组勾股数. 例: 输入:10 输出:1 思路:我是直接暴力破解的…… 首先找出 ...

  9. C语言 · 勾股数

    勾股数 勾股定理,西方称为毕达哥拉斯定理,它所对应的三角形现在称为:直角三角形. 已知直角三角形的斜边是某个整数,并且要求另外两条边也必须是整数. 求满足这个条件的不同直角三角形的个数. [数据格式] ...

随机推荐

  1. java判断姓是否合格 百家姓

    package util; import java.lang.reflect.Array; public class FirstName { public static boolean ClearNa ...

  2. Linux系统的安装(centos的下载地址:http://mirror.symnds.com/distributions/CentOS-vault/6.3/isos/i386/,选择:CentOS-6.3-i386-bin-DVD1.iso 这个下载并进行安装)

    1.首先打开虚拟机: 在上面的那个按钮旁有一个下拉的符号,点开后会看到一个进入固件的按钮,直接点击进去. 便会进入这个界面: 在这个界面其实我们不需要该任何的东西,但是我们需要进入boot界面看一眼, ...

  3. ListView里面adapter的不同分类的item

    public class PlayAdapter extends BaseAdapter { /** * 标题的item */ public static final int ITEM_TITLE = ...

  4. onRetainNonConfigurationInstance方法状态保存

    onRetainNonConfigurationInstance方法作用于ONSAVEINSTANCE类似,但是能保存更多的信息,可以使用getLastNonConfigurationInstance ...

  5. eclipse格式化代码模板

    <?xml version="1.0" encoding="UTF-8" standalone="no"?> <profi ...

  6. 算法Sedgewick第四版-第1章基础-022一QueueWithTwoStacks

    /****************************************************************************** * Compilation: javac ...

  7. 914D Bash and a Tough Math Puzzle

    传送门 分析 用线段树维护区间gcd,每次查询找到第一个不是x倍数的点,如果这之后还有gcd不能被x整除的区间则这个区间不合法 代码 #include<iostream> #include ...

  8. java全栈day02

    今日内容介绍1.变量2.运算符 01变量概述 * A: 什么是变量? * a: 变量是一个内存中的小盒子(小容器),容器是什么?生活中也有很多容器,例如水杯是容器,用来装载水:那么变量是装载什么的呢? ...

  9. SpringMVC 配置式开发-HandlerMapping的执行流程(八)

    具体看这两块是怎么执行的 下图是实现了DispatcherServlet从HandleMapping获得处理器执行链的逻辑的源代码 下面是DispatcherServlet从HandleAdaptor ...

  10. SQL SERVER 取本月上月日期

    select   dateadd(dd,-day(dateadd(month,-1,getdate()))+1,dateadd(month,-1,getdate()))     /*上个月一号*/ s ...