HDU - 6441(费马大定理)
链接: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(费马大定理)的更多相关文章
- hdu 6441 (费马大定理+勾股数 数学)
题意是给定 n 和 a,问是否存在正整数 b,c 满足:a^n + b^n == c^n.输出 b c,若不存在满足条件的 b,c,输出 -1 -1. 当 n > 2 时,由费马大定理,不存在 ...
- HDU 6441 费马大定理+勾股数
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se ...
- HDU 6441 - Find Integer - [费马大定理][2018CCPC网络选拔赛第4题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu 6441 Find Integer(费马大定理+勾股数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6441(本题来源于2018年中国大学生程序设计竞赛网络选拔赛) 题意:输入n和a,求满足等式a^n+b^ ...
- 题解报告:hdu 6441 Find Integer(费马大定理+智慧数)
Problem Description people in USSS love math very much, and there is a famous math problem .give you ...
- 水题两篇 Dream & Find Integer (HDU 6440/6441)
// 出自ICPC 2018网络赛C - Dream & D - Find Integer // 对大佬来讲的水题,本菜鸡尽量学会的防爆零题... // 今晚翻看vjudge昨日任务上的C题, ...
- 【2018 CCPC网络赛】1004 - 费马大定理&数学
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Knowledge Point: 1. 费马大定理:当整数n >2时,关于x, y, z的 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
随机推荐
- Spring使用java代码配置Web.xml进行访问service
方式一:继承WebMvcConfigurerAdapter类 1.使用一个类来继承 package com.wbg.springJavaConfig.spring; import org.spring ...
- 【luogu P2491 [SDOI2011]消防】 题解
题目链接:https://www.luogu.org/problemnew/show/P2491 题外话: OI一共只有三种题--会的题,不会的题,二分题. 题解: step 1 求树的直径,把树的直 ...
- java Thread 类 run 和 start 方法区别
public class ThreadModle { public static void main(String[] args) throws InterruptedException { Thre ...
- 在spring添加注解时,第一行package报错configure build path
练习spring的ioc的注解的时候写上注解就会在第一行package报错configure build path. 用的spring4.2.4的jar包.经过上网查阅资料,可能是jar包冲突,解决办 ...
- ElasticSearch搜索服务技术
ElasticSearch 基于的lucene开发的搜索服务技术;天生支持分布式; Es的结构 gatway:存储层,所有的数据可以存储在本地(多个es节点形成分布式存储),hdfs输出位置,共享文件 ...
- linux下安装rar
1. sudo wget https://www.rarlab.com/rar/rarlinux-x64-5.5.0.tar.gz 2.解压 tar -zxf rarlinux-5.0.1.tar.g ...
- C# Console类的方法使用总结
Console类表示控制台应用程序的标准输入流.输出流和错误流. 此类不能被继承,而在Java中,类似的功能则由System.in和System.out来实现了. 一 输出到控制台 输出到控制台就是把 ...
- Swift_枚举
Swift_枚举 点击查看源码 空枚举 //空枚举 enum SomeEnumeration { // enumeration definition goes here } 枚举基本类型 //枚举基本 ...
- #leetcode刷题之路12-整数转罗马数字
罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值I 1V 5X 10L 50C 100D 500M 1000 例如, 罗马数字 2 写做 II ,即为两个并列的 1.12 ...
- FreeImage 生成带透明通道的GIF
主要方法: 加载图像及读取参数 FreeImage_Load FreeImage_GetWidth FreeImage_GetHeight FreeImage_Allocate FreeImage_G ...