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. 随机森林OOB score作用
  2. c编写程序完成m名旅客和n辆汽车的同步程序代写
  3. SQL:给查询添加一个合计行
  4. E-MapReduce结合DataV进行数据展现
  5. js数组中的find、filter、sort
  6. 人工智能AI实战100讲(二)-自动驾驶传感器之激光雷达(三)主流车厂激光雷达的选择及布局
  7. 线性结构常规操作(四)
  8. EXCEL数据导入dataset
  9. ARP 地址解析协议
  10. tis红石生存服务器后勤系统,我的世界红石生存服务器TIS,真正的大神团队,惊叹世界的杰作...
  11. c语言算星期,计算任何一天是星期几的C语言源代码.
  12. HSRP协议详解:配置HSRP实现网关的冗余备份
  13. 世界500强面试题----反应能力
  14. php 加号转义,URL中加号(+)转义问题
  15. 查看表内容 mysql_mysql查询表内容
  16. 怎么查看电脑系统的初始安装日期
  17. android p 荣耀v10,荣耀V10和V9哪个好 区别对比分析告诉你
  18. 小朋友排队(树状数组)
  19. 开blog记录,咩哈哈
  20. cascade rcnn:delving into high quality object detection

热门文章

  1. Dialog源码分析
  2. tomcat基本知识点与实例
  3. fail2ban安全设置
  4. Goroutine的几个例子
  5. 实践中的电商前端优化
  6. 理解Fragment生命周期
  7. leetcode- Single Number
  8. Javaweb中利用kaptcha生成验证码
  9. 看微信了解MySQL及相关IT技术
  10. 慢慢学Linux驱动开发,第四篇,USB工作原理简单分析