链接: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 远程调试 Tomcat 的方法

    在调试代码的过程中,为了更好的定位及解决问题,有时候需要我们使用远程调试的方法.在本文中,就让我们一起来看看,如何利用 IntelliJ IDEA 进行远程 Tomcat 的调试. 首先,配置remo ...

  2. Redis(RedisTemplate)使用list链表

    RedisTemplate配置:https://www.cnblogs.com/weibanggang/p/10188682.html package com.wbg.springRedis.test ...

  3. Node环境下实现less编译

    今天在学习less的时候发现了在node中是可以渲染的,通过调用less的render方法渲染来生成css,所以写了个小Demo. var less = require('less'); var ht ...

  4. Kindeditor图片上传Controller

    asp.net MVC Kindeditor 图片.文件上传所用的Controller [HttpPost, AllowAnonymous] public ActionResult UploadIma ...

  5. ORACLE学习之三

    DDL 数据定义语言 CREATE ALTER DROP DML 数据操作语言 INSERT UPDATE DELETE DQL 数据查询语言 SELECT TCL 事务控制语言 COMMIT ROL ...

  6. window系统mysql无法输入和无法显示中文的处理配置

    第一步:使用记事本打开mysql安装目录下的"my.ini”文件. # MySQL client library initialization. [client] port= [mysql] ...

  7. margin中的bug解决方法

    margin bug问题 : 当做子元素中使用margin-top: 50px;父子元素都会跑出50px, 解决方法: 在父元素中使用下面三种任意一种都可以. 方法一:给父元素加边框 border: ...

  8. JS 创建对象总结

    狭义:new 构造函数. (注:在JS中创建对象只有一种方式,就是new 构造函数.其中字面量的方式是一种语法糖,本质仍然是new 构造函数) 广义:工厂模式(解决复杂度) 构造函数模式(解决复杂度, ...

  9. HTML 5 audio标签

    audio标签的介绍 定义: <audio> 标签定义声音,比如音乐或其他音频流. <audio></audio>是HTML5中的新标签 能够在浏览器中播放音频, ...

  10. window server IIS组建方法

    文章来自:二度云IIS(Internet Information Server,互联网信息服务)是一种Web(网页)服务组件,其中包括Web服务器.FTP服务器.NNTP服务器和SMTP服务器,分别用 ...