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

2 3

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(勾股数+费马大定理)的更多相关文章

  1. 2018 CCPC网络赛

    2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...

  2. 2018 CCPC网络赛 几道数学题

    1002 Congruence equation 题目链接  : http://acm.hdu.edu.cn/showproblem.php?pid=6439 题解 : https://www.zyb ...

  3. 【2018 CCPC网络赛】1004 - 费马大定理&数学

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Knowledge Point: 1. 费马大定理:当整数n >2时,关于x, y, z的 ...

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

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

  6. 2018 CCPC 网络赛

    The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed ...

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

  8. 【2018 CCPC网络赛】1001 - 优先队列&贪心

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6438 获得最大的利润,将元素依次入栈,期中只要碰到比队顶元素大的,就吧队顶元素卖出去,答案加上他们期中 ...

  9. 【2018 CCPC网络赛】1009 - 树

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6446 题目给出的数据为一棵树,dfs扫描每条边,假设去掉某条边,则左边 x 个点,右边 n-x 个点, ...

随机推荐

  1. 操作系统-Interrupts

  2. Mac下抓包工具Charles4.0下载及使用

    Charles是一款运行在你自己计算机上的web代理工具,可以有效地获取http通信信息,主要用于网页的开发和调试等. 安装 以下为来自史蒂芬周的博客的Charles 4.0 Mac破解版 下载地址: ...

  3. hdu 3642 覆盖3次以上体积

    http://www.cnblogs.com/kane0526/archive/2013/03/06/2947118.html 题目大意:给你n个立方体,求相交区域大于等于三次的体积和. 这题需要前面 ...

  4. BAT的java面试题

    公司:国内三巨头其中的一家!面试时间约在1月份左右!基本上都是在晚上,所以不影响白天上班! 一面 一面偏架构方面 1.介绍一下自己,讲讲项目经历 2.你们项目中微服务是怎么划分的,划分粒度怎么确定? ...

  5. 洛谷P1730 最小密度路径(floyd)

    题意 题目链接 Sol zz floyd. 很显然的一个dp方程\(f[i][j][k][l]\)表示从\(i\)到\(j\)经过了\(k\)条边的最小权值 可以证明最优路径的长度一定\(\leqsl ...

  6. selendroid之inspector

    http://selendroid.io/inspector.html 寻找元素.断点模式.

  7. p2psearcher绿色版使用方法

    P2pSearcher大家应该很了解,p2p是一款基于P2P技术的资源搜索软件,基于先进的P2P搜索技术,可在瞬间搜遍全球ED2k网络资源,简单便捷的搜索到ED2K网络上共享的海量影音娱乐,学习资料等 ...

  8. python入门14 字典dict

    字典dict是无序的key:value格式的数据序列 #coding:utf-8 #/usr/bin/python """ 2018-11-11 dinghanhua 字 ...

  9. libevent-select模型分析

    下面内容为windows下select模型分析,原博客链接 http://blog.csdn.net/fish_55_66/article/details/50352080 https://www.c ...

  10. Waiting on Groups of Queued Tasks

    https://developer.apple.com/library/content/documentation/General/Conceptual/ConcurrencyProgrammingG ...