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. mysql无法连接Can't create a new thread (errno 11)

    问题描述: 今天本地navicat连接服务器mysql出错 ,提示ERROR 1135: Can't create a new thread (errno 11); if you are not ou ...

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

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

  3. flex布局的一些注意点

    现在来总结下自己在项目中用flex布局的一些注意点 1.ui图中的布局方式与justify-content的布局方法不一样 这是就要利用flex-grow的空dom来分开子容器来达到页面布局的效果 2 ...

  4. echarts环形图点击旋转并高亮

    通过计算某个扇形区域的值占整个圆的百分比来得到这个扇形的角度,从而根据startAngle这个属性来设定图形的开始渲染的角度,使点击某个扇形时圆环旋转使之始终对准某个点. 期间考虑到某扇形区域太小点击 ...

  5. 9th week -the history of program 1950~2020

    We already know that programming language is a formal language designed to communicate instructions ...

  6. 靠谱的div引入任何外链内容

    靠谱的div引入任何外链内容 开发中经常要在div中引入一个页面,该页面可能是内部页面,可能是一个外部页面,也可能只是一个域名获取的请求. 对于内部页面的加载,建议使用jquery的load函数,如: ...

  7. Zepto结合Swiper的选项卡

    我们昨天说了关于Angular的选项卡,那今天就说一下Swiper的选项卡吧! 今天的选项卡是Zepto结合Swiper的选项卡,咱么明天再说纯纯的Swiper的吧! 既然是关于Zepto和Swipe ...

  8. Java环境路径配置--转载

    windows环境中JDK环境变量配置   一.环境准备 Windows10 jdk-9.0.1 二.下载并安装JDK 到Java的官网下载JDK安装包,地址:http://www.oracle.co ...

  9. vector/list/set/map 遍历耗时统计

    #include<Windows.h> #include <iostream> #include<fstream> #include<vector> # ...

  10. phpunit 单元测试之代码覆盖率

    最近团队在不断完善项目中的单元测试用例,会用到代码覆盖率分析,本来以为 homestead 应该默认安装了 xdebug ,所以使用 phpunit --coverage-html ./tests/c ...