【2018 CCPC网络赛 1004】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=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
Sample Output
4 5
题意:
本题是Special Judge,共有T组数据,每组数据给出n和a,让我们找到一个符合an+bn=cn的b和c,若不存在输出-1 -1。
思路:
(1) 根据费马大定理可知:当整数n >2时,关于a, b, c的方程 a^n + b^n = c^n 没有正整数解,所以只需讨论n≤2的情况。
(2) 当n=0时,会得到等式1+1=1,显然不可能。
(3) 当n=1时,会得到等式a+b=c,输出符合条件的数据即可。
(4) 当n=2时:
<1> 当a>=3且a=2*x+1(a为奇数,x为正整数)时,b=2x2+2x,c=2x2+2x+1。
<2> 当a>4且a=2*x(a为偶数,x为正整数)时,b=x2-1,c=x2+1。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,a,x;
cin>>t;
while(t--)
{
scanf("%d%d",&n,&a);
if(n==)
printf("%d %d\n",,a+);
else if(n>||!n)
printf("-1 -1\n");
else
{
if(a%==)
{
x=(a-)/;
printf("%d %d\n",*x*x+*x,*x*x+*x+);
}
else if(a%==)
{
x=a/;
printf("%d %d\n",x*x-,x*x+);
}
}
}
return ;
}
【2018 CCPC网络赛 1004】Find Integer(勾股数+费马大定理)的更多相关文章
- 2018 CCPC网络赛
2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...
- 2018 CCPC网络赛 几道数学题
1002 Congruence equation 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6439 题解 : https://www.zyb ...
- 【2018 CCPC网络赛】1004 - 费马大定理&数学
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Knowledge Point: 1. 费马大定理:当整数n >2时,关于x, y, z的 ...
- 2018 CCPC网络赛 hdu6444 Neko's loop
题目描述: Neko has a loop of size n.The loop has a happy value ai on the i−th(0≤i≤n−1) grid. Neko likes ...
- 2018 CCPC 网络赛 Buy and Resell
The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed ...
- 2018 CCPC 网络赛
The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed ...
- 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...
- 【2018 CCPC网络赛】1001 - 优先队列&贪心
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6438 获得最大的利润,将元素依次入栈,期中只要碰到比队顶元素大的,就吧队顶元素卖出去,答案加上他们期中 ...
- 【2018 CCPC网络赛】1009 - 树
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6446 题目给出的数据为一棵树,dfs扫描每条边,假设去掉某条边,则左边 x 个点,右边 n-x 个点, ...
随机推荐
- libtar 和 libz 的使用
libtar 和 libz 的使用 用c代码生成 tar.gz 文件 实现的功能和 tar -zcf 命令一样 大概流程为 1.先用libtar相关函数对某个目录生成tar文件 2.然后对tar文件 ...
- Python爬虫之requests模块(2)
一.今日内容 session处理cookie proxies参数设置请求代理ip 基于线程池的数据爬取 二.回顾 xpath的解析流程 bs4的解析流程 常用xpath表达式 常用bs4解析方法 三. ...
- JS自定义手机端H5键盘
在输入车牌号的时候,因为很多车牌号都是数字字母混合排列的,所以如果用输入法输入就需要频繁切换数字跟字母,有点麻烦. 在这里我们就用自定义一个弹出框代替键盘来使用. 1.首先,要禁止掉文本框弹出输入法, ...
- html的标签(1)
首先补充上一次没有讲到的,html文件后缀名有2种,一种是.htm,一种是.html..html是老的教科书里面的文件后缀名,.html是新的教科书的文件后缀名..htm文件是不完整的支持html5的 ...
- jQuery小测验
1.在div元素中,包含了一个<span>元素,通过has选择器获取<div>元素中的<span>元素的语法是? 提示使用has() $(div:has(span) ...
- Unity Android 真机调试
官方文档 https://docs.unity3d.com/Manual/AttachingMonoDevelopDebuggerToAnAndroidDevice.html 然而 按照官方文档 很多 ...
- SQL 数据匹配更新
萌新的成长之路! 最近遇到的一个需求是需要将两张关联的表的数据进行匹配(dbo.SystemUser[系统用户表]:dbo.V_Temp[系统权限视图]),即通过匹配用户ID与系统ID(拥有的系统ID ...
- Oracle DG 三种模式(转)
DG有下面三种模式– Maximum protection– Maximum availability– Maximum performance 在Maximum protection下, 可以保证从 ...
- 深入浅出C/C++中的正则表达式库
写在前面: 本文是面向有正则表达式基础的读者朋友的,如果你还不知道正则表达式是什么,请先到这里学习一下 :http://en.wikipedia.org/wiki/Regular_expressio ...
- 简单的PHP算法题
简单的PHP算法题 目录 1.只根据n值打印n个0 2.根据n值打印一行 0101010101010101010101…… 3.根据n值实现1 00 111 0000 11111…… 4.根据n值实现 ...