题目传送门

题目大意:

给出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. Spring注解-TaskScheduler

    一.定义配置类 import org.springframework.context.annotation.ComponentScan; import org.springframework.cont ...

  2. 理解和正确使用Java中的断言(assert)

    一.语法形式:    Java2在1.4中新增了一个关键字:assert.在程序开发过程中使用它创建一个断言(assertion),它的语法形式有如下所示的两种形式:1.assert conditio ...

  3. php中用大括号把?>和<?php框起来的作用

    <?php function my_function() { ?> My function was called <!--就是这里,为什么前面要用?>和< ?php 把M ...

  4. Angular问题01 创建组件时报错、HammerJS找不到

    1 利用ng创建组件时出现错误 1.1 ng g c test/testHome 1.2 问题描述 当angular应用中有多个module.ts文件时,创建组件时会出现冲突,因为有多个module. ...

  5. js 控制标记样式

    做一个变色的标签 鼠标移入变为灰色,移除变回原来的颜色,点击变成黑色,再点击变回,如果变成黑色不受移入移除影响. <body> <div class="bt1" ...

  6. Zbar 大图像分析

    博客转载自:https://blog.csdn.net/sunflower_boy/article/details/50429252 为了减少处理时间,可以设定更大的扫描间距,减少不必要的解码类型,去 ...

  7. cf123E Maze

    传送门 分析 见ptx大爷的博客 代码 #include<iostream> #include<cstdio> #include<cstring> #include ...

  8. Entity Framework Code-First(19):Seed Data

    Seed Database in Code-First: You can insert data into your database tables during the database initi ...

  9. 打印sql语句

    root->trace hibernate->trace ,然后,改配置 全文搜索:show_sql,将所有的show_sql改为true. 这样,就会显示sql语句了.

  10. c#桌面应用程序开发--登陆窗口

    一.显示登陆窗口 应用程序入口点为Main方法,因此在Main方法中创建登陆窗体. 1)创建登陆窗体(登陆窗体UI已提前创建好); 2)显示窗体,以模式对话框的形式显示,并赋值给result; 3)判 ...