链接:HDU - 6441

题意:已知 n,a,求 b,c 使 a^n + b^n = c^n 成立。

题解:费马大定理

1.a^n + b^n = c^n,当 n > 2 时无解;

2.

当 a 为奇数

a = 2 * k + 1;

c = k ^ 2 + (k + 1) ^ 2;

b = c - 1;

当 a 为偶数

a = 2 * k + 2;

c = 1 + (k + 1) ^ 2;

b = c - 2;

#include <bits/stdc++.h>
using namespace std; const double EPS = 1e-;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
const int maxn = 1e5 + ;
long long n, a, b, c; int main()
{
int T;
scanf("%d", &T);
while(T--){
scanf("%lld%lld", &n, &a); if(n == || n > ){
puts("-1 -1");
continue;
} if(n == ){
printf("%lld %lld\n", a, a<<);
continue;
} if(a & 1LL){
long long k = a / ;
c = k * k + (k + ) * (k + );
b = c - ;
}
else{
long long k = a / - ;
c = + (k + ) * (k + );
b = c - ;
} printf("%lld %lld\n", b, c);
} return ;
}

HDU - 6441(费马大定理)的更多相关文章

  1. hdu 6441 (费马大定理+勾股数 数学)

    题意是给定 n 和 a,问是否存在正整数 b,c 满足:a^n + b^n == c^n.输出 b  c,若不存在满足条件的 b,c,输出 -1 -1. 当 n > 2 时,由费马大定理,不存在 ...

  2. HDU 6441 费马大定理+勾股数

    #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se ...

  3. HDU 6441 - Find Integer - [费马大定理][2018CCPC网络选拔赛第4题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  4. hdu 6441 Find Integer(费马大定理+勾股数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441(本题来源于2018年中国大学生程序设计竞赛网络选拔赛) 题意:输入n和a,求满足等式a^n+b^ ...

  5. 题解报告:hdu 6441 Find Integer(费马大定理+智慧数)

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

  6. 水题两篇 Dream & Find Integer (HDU 6440/6441)

    // 出自ICPC 2018网络赛C - Dream & D - Find Integer // 对大佬来讲的水题,本菜鸡尽量学会的防爆零题... // 今晚翻看vjudge昨日任务上的C题, ...

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

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

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. 十二、IntelliJ IDEA 中的版本控制介绍(中)

    由于 IntelliJ IDEA 支持的版本控制工具非常的多,但咱们真正能够用到的也就两三个而已,因此在本篇博文中,咱们主要介绍 SVN.Git 和 GitHub 的配置方法. SVN 如果想要在 I ...

  2. spring配置redis(xml+java方式)(最底层)

    条件:引用好架包 <dependency> <groupId>org.springframework.data</groupId> <artifactId&g ...

  3. OSMboxPost()

    1.向邮箱发送一则消息 2.原型:INT8U OSMboxPost(OS_EVENT *pevent, void *msg) 3. pevent: 消息邮箱指针(ECB指针) msg:   消息指针 ...

  4. SVN 操作报错 “Previous operation has not finished; run 'cleanup' if it was interrupted“

    今天在 通过 SVN 合并代码的时候报了如下的错误 ”Previous operation has not finished; run 'cleanup' if it was interrupted“ ...

  5. Maven项目改为spring boot项目的方法

    目录树 新建Maven项目及步骤 修改方法 启动测试 新建Maven项目及步骤 我这里是从创建开始讲,使用的工具是Idea2017版本.如果是已经创建了Maven,想改为spring boot项目的请 ...

  6. docker build

    nginx Docfile ----------------------- FROM centos   MAINTAINER daniel   RUN yum install -y wget RUN ...

  7. 文件后缀与Mime类型对照表

    以下是一些文件后缀(扩展名)对应的MIME类型的一个对照表,方便iis中或其他服务器对相应的文件进行解析.有些文件的后缀名没有默认解析就出现上传后无法访问或者下载的问题,这个时候就要设置文件后缀对应的 ...

  8. PHP防止数字太大转化为科学计数法的方法

    PHP当数字在20位或者20位以上时,会转化为科学计数法 例子: <?phpecho 11111111111111111111; ?> 解决方法可以使用php函数number_format ...

  9. Java Integer == 以及分析

    Java Integer == 先看一下这段代码 Integer integer1 = 100; Integer integer2 = 100; System.out.println("in ...

  10. go内建容器-切片

    1.基础定义 看到'切片'二字,满脸懵逼.切的啥?用的什么刀法切?得到的切片有什么特点?可以对切片进行什么操作? 先看怎么得到切片,也就是前两个问题.切片的底层是数组,所以切片切的是数组:切的时候采用 ...