题意:题意:给你两个数 n ,a,要求输出b,c,满足an+bn=cna^n+b^n=c^nan+bn=cn ,否则输出-1,-1

分析:根据费马大定理内容:当整数 n > 2时,关于x, y, z的方程xn+yn=znx^n + y^n = z^nxn+yn=zn 没有正整数解。
所以①当 n > 2 或 n = 0时无解,输出-1,-1。
②当 n == 2时,将公式变形:a2+b2=c2⟹a2=c2−b2⟹a2=(c+b)(c−b)a^2+b^2=c^2 \\ \implies a^2=c^2 - b^2 \\ \implies a^2 = (c +b) (c - b)a2+b2=c2⟹a2=c2−b2⟹a2=(c+b)(c−b),从a2a^2a2的约数里找两个不同的值,满足条件即可。具体实现看代码。

  • 注意:选择的 ret / i 和 i 相当于 (c +b) 和 (c - b),它俩的和还需满足是偶数。

accode:

#include <stdio.h>
typedef long long ll;
ll a, b, c, n;
inline ll max(ll x, ll y){return (x > y) ? x : y;}int main()
{int T;scanf("%d", &T);while(T--){scanf("%lld %lld", &n, &a);if(n == 0 || n > 2)printf("-1 -1\n");else if(n == 1)printf("1 %lld\n", a + 1);else{ll ret = 1ll * a * a;for(ll i = 1; i <= a; i++){if(ret % i == 0 && ret % (ret / i) == 0 && i != ret / i && (ret / i + i) % 2 == 0){c = (i + ret / i) / 2;b = max(i, ret / i) - c;break;}}printf("%lld %lld\n", b, c);}}return 0;
}

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

  1. HDU 6441 Find Integer 【费马大定理】

    传送门:HDU 6441 Find Integer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...

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

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

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

  4. 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 ...

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

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

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

  7. HDU 6441 Find Integer

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

  8. HDUOJ 6441 Find Integer

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

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

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

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

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

最新文章

  1. Android微信智能心跳方案 Android微信智能心跳方案
  2. android 学习笔记之图形算法
  3. 机器学习的发展和硬件发展的关系
  4. 微软2021校园招聘正式启动
  5. 开箱即用——用这个模板快速统筹企业车辆安排
  6. 计算机连接拒绝访问,Win10系统下Windows无法连接到打印机,拒绝访问的解决办法...
  7. 物联网初步之电阻性电路分析 第三部分 电路分析方法和电路原理
  8. 你应该知道的Windows复制技术
  9. 不可错过的MSDN TV —— IronPython: Python on the .NET Framework (中)
  10. 【HTML+CSS】静态网页设计期末大作业——我的家乡无锡印象
  11. STM32中使用MMA7660重力加速度传感器
  12. 联想y7000笔记本触摸板开启快捷键_联想 拯救者Y7000P 如何关闭触摸板?
  13. 恒生电子23届校招内推
  14. http://www.jobui.com/mianshiti/it/java/6782/
  15. Android面试题4
  16. Linux挂载Windows网络共享文件夹
  17. 经典例题C语言程序解决数学问题
  18. 【面向对象】Java面向对象内容
  19. Q-dir 被默认设置为 资源管理器
  20. Sharding-Sphere的新一代Zookeeper注册中心实现剖析

热门文章

  1. 股市中如何用筹码分布选牛股,通达信幅图指标公式筹码寻牛
  2. 研究生如何学习与科研的几点建议——来自一枚菜博的愚见
  3. 自动化产线自动刀补实现
  4. 痛并快乐着的研究生学习生涯(4)-9.4
  5. 华硕主板如何用u盘启动计算机,最新华硕主板bios设置u盘启动教程
  6. 教你设置QQ空间个性签名档
  7. 《计算机网络》读书笔记
  8. Flutter 基础布局之Stack
  9. excel 行列互换 绿色工具(怎么把行变成列,把列变成行)
  10. 笔记本电脑WIN10开热点手机无法连接的问题