HDU 6441 Find Integer(费马大定理)
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
题解:此题考察费马大定理,当n>=3时,a的n次方+b的n次方=c的n次方,将没有整数解,所以这个题只需判断,n=1和n=2的情况就好了,我们接下来,还要提一下,当n=2时,你需要点开
https://wenku.baidu.com/view/8282f1b669eae009591bec85.html
这个神奇的链接看一下。
AC代码:
#include<stdio.h>
int main()
{long long T,n,a;scanf("%lld",&T);while(T--){scanf("%lld%lld",&n,&a);if(n>=3||n==0){printf("-1 -1\n");}else if(n==1){printf("%lld %lld\n",a+1,2*a+1);}else if(n==2){if(a%2!=0){printf("%lld %lld\n",a*(a/2)+a/2,a*(a/2)+a/2+1);}else{printf("%lld %lld\n",(a*(a/2))/2-1,(a*(a/2))/2+1);}}}return 0;
}
HDU 6441 Find Integer(费马大定理)相关推荐
- HDU 6441 Find Integer 【费马大定理】
传送门:HDU 6441 Find Integer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- 【2018-CCPC青岛网赛】 HDU - 6441 Find Integer
[2018-CCPC青岛网赛] HDU - 6441 Find Integer 源链接: HDU - 6441 文源 :Blog 题意 已知等式,a^n + b ^ n = c ^ n,题目中给出 a ...
- hdu.6441 Find Integer
hdu.6441 Find Integer 思路:费马大定理+勾股定理. 费马大定理内容:an+bn=cn,(n>2)a^n+b^n=c^n,(n>2)an+bn=cn,(n>2)时 ...
- 【hdu】6441 Find Integer - 费马大定理
Find Integer 题解: 根据费马大定理很容易知道当 n>2 时,等式 a^n+b^n=c^n 是无整数解的. 再假设当 n=0 时,a^0=1.题目中说到 (1≤b,c≤1000,00 ...
- HDU 6441 Find Integer(数论)
Description 给出n,an,an,a,求一组b,cb,cb,c使得an+bn=cna^n+b^n=c^nan+bn=cn Input 第一行一整数TTT表示用例组数,每组用例输入两个整数n, ...
- HDU 6441 Find Integer
题目传送门 代码: #include<bits/stdc++.h> using namespace std;int main(){int T;scanf("%d",&a ...
- HDUOJ 6441 Find Integer
HDUOJ 6441 Find Integer 题目链接 Problem Description people in USSS love math very much, and there is a ...
- 【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)
题干: people in USSS love math very much, and there is a famous math problem . give you two integers n ...
- hdu 6441 (费马大定理+勾股数 数学)
题意是给定 n 和 a,问是否存在正整数 b,c 满足:a^n + b^n == c^n.输出 b c,若不存在满足条件的 b,c,输出 -1 -1. 当 n > 2 时,由费马大定理,不存在 ...
最新文章
- 前端开发--播放页面评论区业务逻辑初步
- IIS中 flv、swf 文件无法播放
- MySQL常用语句一、连接MySQL格式:mysql-h主机地址-u用户名-p用户密
- 取消chrome浏览器下input和textarea的默认样式
- 《天天数学》连载41:二月十日
- 工作学习资料备份记录
- 2016/1/14 java随机数生成
- 详解Nginx的功能策略配置
- 动态时间规整算法_如何使用动态时间规整算法进行语音识别
- 计算机重启后一直黑屏转圈,电脑win10开机黑屏转圈十几秒怎么解决
- (论文)Persuading Customers to Buy Early: The Value of Personalized
- 针对传感网的数据管理系统结构有_2010年自考管理信息系统模拟试题及答案(三)...
- 如何做好App性能测试
- 基于图搜索的规划算法之Voronoi图法
- sql server 替换字段中的部分字符,替换指定字符的方法
- 谷歌浏览器双击打不开pdf问题
- 解决Worker 1 failed executing transaction ‘ANONYMOUS‘ at master log mall-mysql-bin.000001, end_log_pos
- Watir vs. SilkTest
- pip is not an internal or external command how to solve pip 不是内部或外部命令 ------解决方法 顺便把pip升级
- 推动长三角信创产业发展 华云数据承办的“十四五”规划系列座谈会信创专场顺利召开