HDU 6441 Find Integer 费马大定理
题意:题意:给你两个数 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 费马大定理相关推荐
- 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(费马大定理)
people in USSS love math very much, and there is a famous math problem . give you two integers n,a,y ...
- 【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 时,由费马大定理,不存在 ...
最新文章
- Android微信智能心跳方案 Android微信智能心跳方案
- android 学习笔记之图形算法
- 机器学习的发展和硬件发展的关系
- 微软2021校园招聘正式启动
- 开箱即用——用这个模板快速统筹企业车辆安排
- 计算机连接拒绝访问,Win10系统下Windows无法连接到打印机,拒绝访问的解决办法...
- 物联网初步之电阻性电路分析 第三部分 电路分析方法和电路原理
- 你应该知道的Windows复制技术
- 不可错过的MSDN TV —— IronPython: Python on the .NET Framework (中)
- 【HTML+CSS】静态网页设计期末大作业——我的家乡无锡印象
- STM32中使用MMA7660重力加速度传感器
- 联想y7000笔记本触摸板开启快捷键_联想 拯救者Y7000P 如何关闭触摸板?
- 恒生电子23届校招内推
- http://www.jobui.com/mianshiti/it/java/6782/
- Android面试题4
- Linux挂载Windows网络共享文件夹
- 经典例题C语言程序解决数学问题
- 【面向对象】Java面向对象内容
- Q-dir 被默认设置为 资源管理器
- Sharding-Sphere的新一代Zookeeper注册中心实现剖析