HDUOJ 6441 Find Integer
HDUOJ 6441 Find Integer
题目链接
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>2n>2n>2 时,一定无正整数解~
当 n=0n=0n=0 时,显然无解~
当 n=1n=1n=1 时,输出 111 和 a+1a+1a+1 即可
当 n=2n=2n=2 时,注意题目限定必须是正整数,我们考虑分奇偶,对 aaa 为奇数,a2a^2a2 可以拆分成 a2∗1a^2*1a2∗1;对 aaa 为偶数,a2a^2a2 可以拆分成 a22∗2\frac{a^2}{2}*22a2∗2,分别解一个二元一次方程即可~
注意输出的顺序,AC代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T,n,a;
int main(){scanf("%d",&T);while(T--){scanf("%d%d",&n,&a);if(n>2||n==0) printf("-1 -1\n");else if(n==2){if(a%2) printf("%d %d\n",(a*a-1)/2,(a*a+1)/2);else printf("%d %d\n",a*a/4-1,a*a/4+1);}else if(n==1){printf("1 %d\n",a+1);}}return 0;
}
HDUOJ 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
题目传送门 代码: #include<bits/stdc++.h> using namespace std;int main(){int T;scanf("%d",&a ...
- 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 CCPC网络选拔赛 6441 Find Integer(数学)
费马大定理只只有n=1或n=2时候才会有解 当n=2时,即满足勾股定理 一, 直角三角形a^2+b^2=c^2的a值奇偶数列法则: 定理1. 如a^2+b^2=c^2是直角三角形的三个整数边长,则必有 ...
- 【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)
题干: people in USSS love math very much, and there is a famous math problem . give you two integers n ...
最新文章
- html5简单游戏案例,HTML5存储(带一个粗糙的打怪小游戏案例)
- 通过iframe引入另外一个项目中的html片段到项目中,解决样式,高度,兼容等问题的策略
- Homework 8 测试计划
- Hyperledger Fabric 实战(七):链码 shim API 详解
- 简单的文本文件加密小程序
- 李迅雷:大城市化和居民加杠杆能支撑房价多久
- vue公式编辑器 加强版(简化版)
- 计算机时代汉字书写有了新的方式,网络时代的汉字书写
- 机器人关节控制硬件知识——伺服电机、驱动器、控制器
- 基于FPGA的UART串口通信实验(VHDL语言实现)
- 交叉编译arm版linaro-1.13.1-4.7-2013.03
- ubuntu 网速测试方法
- iOS 12+ ReplayKit 系统录屏(一)
- 云和恩墨亮相CNCC 2020,zCloud打造国产时代数据库管理中台
- unity如何改变重力方向
- 马士兵学习笔记-Java基础网络编程
- 如何加强幼儿园安全管理
- Android中实现平铺图片
- win7企业版安装vmtool提示无法进行,需要更新到SP1。【不换镜像,已解决】
- Win7、windows 2008 IIS7.5下载安装方法以及教程 IIS7配置PHP环境图文教程(fastcgi快速最新版)