传送门:HDU 6441


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

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=cna^n+b^n=c^nan+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>2 时,关于 x,y,z 的方程 xn+yn=znx^n+y^n=z^nxn+yn=zn 没有正整数解。

  • 当 n > 2 时,直接输出 -1 -1 ;
  • 当 n = 0,也是无解,输出-1 -1;
  • 当 n = 1,即 a + b = c,已知 a ,令 b = 1,c = a + 1 即可
  • 当 n = 2,对于 x2+y2=z2x^2 + y^2 = z^2x2+y2=z2,如果已知x,那么就有z2−y2=x2z^2-y^2=x^2z2−y2=x2
    因为 z > y,所以设 z = y + i
    那么就有:
    x2−i2=2∗i∗yx^2 - i^2 = 2*i*yx2−i2=2∗i∗y
    只要枚举 i ,判断(x^2 - i^2)% 2*i 是否可以整除即可

AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#define ll long long
#define inf 0x3f3f3f3f
int t;
ll n;
ll a;
int main()
{scanf("%d",&t);while(t--){scanf("%I64d%I64d",&n,&a);if(n>2||n==0){printf("-1 -1\n");}else if(n==1){printf("1 %I64d\n",1+a);}else{a=a*a;ll b,c;for(ll i=1;;i++){if((a-i*i)%(2*i)==0){b=(a-i*i)/(2*i);c=b+i;break;}}printf("%I64d %I64d\n",b,c);}}return 0;
}

HDU 6441 Find Integer 【费马大定理】相关推荐

  1. 【2018-CCPC青岛网赛】 HDU - 6441 Find Integer

    [2018-CCPC青岛网赛] HDU - 6441 Find Integer 源链接: HDU - 6441 文源 :Blog 题意 已知等式,a^n + b ^ n = c ^ n,题目中给出 a ...

  2. 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)时 ...

  3. HDU 6441 Find Integer(费马大定理)

    people in USSS love math very much, and there is a famous math problem . give you two integers n,a,y ...

  4. 【hdu】6441 Find Integer - 费马大定理

    Find Integer 题解: 根据费马大定理很容易知道当 n>2 时,等式 a^n+b^n=c^n 是无整数解的. 再假设当 n=0 时,a^0=1.题目中说到 (1≤b,c≤1000,00 ...

  5. 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, ...

  6. HDU 6441 Find Integer

    题目传送门 代码: #include<bits/stdc++.h> using namespace std;int main(){int T;scanf("%d",&a ...

  7. HDUOJ 6441 Find Integer

    HDUOJ 6441 Find Integer 题目链接 Problem Description people in USSS love math very much, and there is a ...

  8. 【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)

    题干: people in USSS love math very much, and there is a famous math problem . give you two integers n ...

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

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

最新文章

  1. 主存储器是现代计算机系统的数据传送中心,第2章计算机体系结构习与题答案.doc...
  2. day 33(套接字,TCP 与 UDP)
  3. 神策数据助力海通证券,精耕 4 大场景,全面强化数字化运营
  4. 如何更加进一步的找到相关的信息呢?
  5. 自学python前戏
  6. 第四周 Access总结
  7. Nmap 可能引起cisco路由器Crash
  8. 基于GXWorks2的ST语言介绍
  9. 彼得•林奇基层调查选股法(GARP股票投资策略)
  10. 关于2022年电改政策的解读
  11. 蓝桥杯 2014真题 史丰收速算
  12. DC离职率预测案例分析
  13. 【UV打印机】理光喷头组合说明(24H)
  14. SD卡CF卡U盘硬盘等磁盘属性显示为0字节怎么恢复数据
  15. 外泌体介绍 - MedChemExpress
  16. 产品经理——关于版式设计!!
  17. 2020新基建人才薪资:工业互联网月薪1.81万元居首,超5G、人工智能
  18. show version命令
  19. Node.js的认识(初级教程)
  20. “善于治”和“以善治”:华为云Stack在智慧城市的十年踪迹十年心

热门文章

  1. 超级计算机的性能指标
  2. android实现发送短信的功能
  3. warcraft 3 经典语句之月之女祭司(Priestess of the moon)
  4. NVIDIA CUDA初级教程(P2-P3)CPU体系架构概述、并行程序设计概述
  5. 三面字节跳动被虐得“体无完肤”,15天读完这份pdf,终拿下美团研发岗offer
  6. 化工集团如何制定数字化转型策略
  7. java 将json写入txt_关于json:在java中将String写入文本文件
  8. Google与百度、搜狗合作,共同推进移动网络发展
  9. Bert 得到中文词向量
  10. cocos2dx 植物大战僵尸 5 塔基Terrain的更新