题目传送门

题目大意:

给出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. JS写一个简单的程序,输入两个整数,打印这两个数的和,差,积,余数

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. js分页demo

    纯js实现分页   原理:所有数据已加载好,js通过遍历部分显示,实现分页效果 html代码 <html> <head> <meta charset='utf-8'> ...

  3. 0016_练习题d2

    __author__ = 'qq593' #!/usr/bin/env python #-*- coding:utf-8 -*- #元素分类,有如下值集合[11,22,33,44,55,66,77,8 ...

  4. 中华人民共和国建筑工业行业标准—IFC详细解读 第五篇

  5. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-006归并排序(Mergesort)

    一. 1.特点 (1)merge-sort : to sort an array, divide it into two halves, sort the two halves (recursivel ...

  6. Windows Live Writer 使用指南

    一.简介 Windows Live Writer 是一个强大的离线博客编辑工具,通过它可以离线编辑内容丰富的博文,除了自身强大的编辑功能之外,还提供了接口,让其它开发人员通过插件提供工具自身没有提供的 ...

  7. R: 关于 ggplot2 的初探

    生活还很长,别急,慢慢来.亲爱的 require(ggplot2)p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point() ; p1p1 + scale ...

  8. 8.View类

    Basic Concepts      在Modle/View 结构中,View从Model中提取数据,并显示给用户.View显示数据的方式不一定与Model中数据排列方式相同,也可能与底层数据结构完 ...

  9. python3-file的修改实现类似shell中sed的功能

    # Auther: Aaron Fan '''思路:目的是为了修改yesterday这个文件,但是因为无法直接去修改这个文件,所以需要先把修改好的内容写入高yesterday.new这个文件中,然后再 ...

  10. 12. git常用语法总结

    git介绍与安装这里不再多说,再说也不如廖雪峰大佬总结的优秀: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67 ...