【hdu】6441 Find Integer - 费马大定理
Find Integer
题解:
根据费马大定理很容易知道当 n>2 时,等式 a^n+b^n=c^n 是无整数解的。
再假设当 n=0 时,a^0=1。题目中说到 (1≤b,c≤1000,000,000) ,所以此时等式也是无解的。
所以,我们只需要再分 n=1 和 n=2 两种情况讨论即可。
当 n=1 时,这里就不说了。
当 n=2 时,又分为奇偶两种情况。
①奇数时,我们设 c=b+1,代入式子化简可得 2*b+1=a^2 ,利用这条式子可以求出b,c。
②偶数时,我们设 c=b+2,同理可求出b,c。
代码:
#include <cstdio>
using namespace std;
int main(){int t;int n, a;scanf("%d", &t);while(t--){scanf("%d %d", &n, &a);if(n==1)printf("1 %d\n", a+1);else if(n==2){if(a&1){int b = (a*a-1)>>1;printf("%d %d\n", b, b+1);}else {int b = (a*a-4)>>2;printf("%d %d\n", b, b+2);}}else printf("-1 -1\n");}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(数论)
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 时,由费马大定理,不存在 ...
最新文章
- 闲话WPF之二四(WPF中的ControlTemplate [2])
- am335x PDK3.0 设置为单网口配置记录
- 小程序点击地图气泡获取气泡_气泡上的气泡
- 计算机技术中,下列的英文缩写和中文名字的对照中,正确的是,计算机技术中,下列的英文缩写和中文名字的对照中。正确的是( )。 a.cad——计算机辅助制造b.cam——计...
- eval函数pythonmopn_pytorch:model.train和model.eval用法及区别详解
- debug运行时出现错误unicodedecodeerror_怎么回事??抖音直播伴侣!出现运行错误...
- Makefile 教程(超详细)
- MATLAB的简单动画制作
- shell--bash变量
- [活动]和Jeffery大师的最近距离
- Axure绘制跑马灯
- 网络世界有哪些不为人知的秘密?
- win10图标重建缓存_如何在Windows 10中重建损坏的图标缓存
- 模电学习笔记(上交郑老师)1.PN结
- windows程序窗口
- Exploring Branch Predictors for Constructing Transient Execution Trojans
- 实名举报!想换高工资的工作——计算机,这让我还怎么样找工作?
- libpng error: iTXt: chunk data is too large error: PNG unsigned integer out of range
- hdu4784 Dinner Coming Soon BFS
- 虹科案例|nanoGUNE应用Onyx系统实现石墨烯电学性质的无损表征
热门文章
- 共享锁和排他锁的区别
- 计算机专业要求屏幕吗,台式电脑需要剪辑的话,显示屏是选择曲屏好还是直屏好呢?...
- DIV布局`电影在线 网站设计——漫威电影(2页) HTML+CSS+JavaScript 学生DW网页设计作业成品
- 抖音直播用什么手机效果最好 抖音直播手机哪款好2023
- ppt转换成pdf免费软件
- matlab学习增强学习,使用 MATLAB 和 Simulink 进行强化学习
- 『杭电1859』最小长方形
- 利用脚手架工具搭建一个新的react项目
- 牛客——The Chivalrous Cow(bfs板题)
- Smart3D系列教程6之 《案例实战演练3——倾斜数据正射影像及DSM的生产》