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

 

1 2 3

Sample Output

 

4 5

费马大定理在加上勾股数的一些规律:

费马大定理:

a^n+b^n=c^n在n>2时是不成立的。

勾股数规律:

https://wenku.baidu.com/view/8282f1b669eae009591bec85.html

#include <iostream>
using namespace std;

int main()      
{
    int T;
    scanf("%d",&T);
    int n,a,b,c;
    while(T--)
    {
        scanf("%d %d",&n,&a);
        if(n>2||n==0)
        {
            printf("-1 -1\n");
            continue;
        }
        else if(n==1)
        {
            printf("%d %d\n",1,a+1);
            continue;
        }
        else
        {
            if(a%2==0)          //a为偶数的时候
            {
                int temp=(a-2)/2;
                printf("%d %d\n",temp*temp+2*temp,temp*temp+2*temp+2); 
                continue;
            } 
            else
            {
                int temp=(a-1)/2;
                printf("%d %d\n",2*temp*temp+2*temp,2*temp*temp+2*temp+1);
                continue;
            }
        }
    }                
    return 0;    
}

Find Integer(费马大定理的使用)相关推荐

  1. 【hdu】6441 Find Integer - 费马大定理

    Find Integer 题解: 根据费马大定理很容易知道当 n>2 时,等式 a^n+b^n=c^n 是无整数解的. 再假设当 n=0 时,a^0=1.题目中说到 (1≤b,c≤1000,00 ...

  2. 【HDU - 6441】Find Integer (费马大定理 + 奇偶数列法构造勾股定理)

    题干: people in USSS love math very much, and there is a famous math problem . give you two integers n ...

  3. hdu6441 Find Integer 求勾股数 费马大定理

    题目传送门 题目大意: 给出a和n,求满足的b和c. 思路: 数论题目,没什么好说的. 根据费马大定理,当n>2时不存在正整数解. 当n=0或者1时特判一下就可以了,也就是此时变成了一个求勾股数 ...

  4. HDU 6441 Find Integer 【费马大定理】

    传送门:HDU 6441 Find Integer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...

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

  6. HDU-6441-Find Integer(费马大定理+勾股数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Problem Description people in USSS love math ver ...

  7. Find Integer - hdu6441 - 费马大定理+奇偶数列法则

    题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=6441 思路: 输入n, 若n>2由费马大定理知无解.输出-1 -1,n=0时也无解,输出-1 - ...

  8. HDUOJ 6441 Find Integer

    HDUOJ 6441 Find Integer 题目链接 Problem Description people in USSS love math very much, and there is a ...

  9. hdu6441 Find Integer

    Problem Description people in USSS love math very much, and there is a famous math problem . give yo ...

最新文章

  1. Datawhale专访 | 周涛:从窄门进最终走出宽路来
  2. UniT | Facebook发布全新智能通用Agent!
  3. SQL Server查询重复数据
  4. Cadence IC CDB-OA工艺库转换方法
  5. hbase hbck命令示例
  6. 怎么使用jstack精确找到异常代码
  7. 基于Huffman算法的文件解压缩
  8. mysql插入timeStamp类型数据时间相差8小时的解决办法
  9. 创建 floating IP - 每天5分钟玩转 OpenStack(106)
  10. 吴恩达机器学习练习3:Logistic regression(Multi-class Classification)
  11. asp. net sql网上书店管理系统设计作品
  12. SpringBoot之kafka安装windows
  13. VS2017注册之找不到输入key的地方的解决方法
  14. 良心安利动物 恐龙unity3d模型素材网站
  15. matlab 仿真 毕业设计,毕业设计matlab仿真
  16. java操作mysql临时表_MySQL 临时表
  17. CNT-以太网帧和IEEE802.3帧
  18. 如何把自家孩子培养成一个顶尖人才(转自微信公众号——紫竹张先生)
  19. 交换机短路_交换机环路发现及处理
  20. 投资组合风险收益率公式_投资组合分析的基础收益和亏损

热门文章

  1. OOP_由C到C++
  2. 使用Xamarin实现跨平台移动应用开发
  3. C算法编程题(一)扑克牌发牌
  4. ストアドプロシージャ(存储过程)
  5. mysql 联合索引详解
  6. 2020 操作系统第二次习题
  7. spring boot基础配置
  8. K8S批量scale deploy的副本为0,结合xargs -I使用
  9. vue v-for指令
  10. vscode linux版下载地址