【2018 CCPC网络赛】1004 - 费马大定理&数学
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6441
Knowledge Point:
1. 费马大定理:当整数n >2时,关于x, y, z的方程 x^n + y^n = z^n 没有正整数解。
2. 0^0次没有意义!!
所以我们知道 n=0, n>2的时候都没有正整数解;
n=1 时显然 b=1, c=a+1 为一组整数解;
n=2 时,a2 = c2-b2 = (c+b)*(c-b);
令x = c+b, y = c-b; 则有 a2 = x*y; b = (x-y)/2, c = (x+y)/2;
因为 b, c 都是正整数,故有 x>y, 且 x, y 奇偶性相同;
当 a为奇数时,x = a2 , y = 1;
当 a为偶数时,a2 和 1一奇一偶,不满足条件,故可令 x = a2/ 2, y = 2;
另外注意数据输入量过大,用 scanf 避免超时;
#include<iostream>
#include<cstdio>
using namespace std; int main()
{
int T, n, a;
scanf("%d", &T); while(T--) {
scanf("%d %d", &n, &a); if(!n || n>) printf("-1 -1\n");
else {
if(n == ) printf("%d %d\n", , a+);
else {
int t = a*a;
if(a&) printf("%d %d\n", (t-)/, (t+)/);
else printf("%d %d\n", t/-, t/+);
}
}
}
return ;
}
【2018 CCPC网络赛】1004 - 费马大定理&数学的更多相关文章
- 【2018 CCPC网络赛 1004】Find Integer(勾股数+费马大定理)
Problem Description people in USSS love math very much, and there is a famous math problem . give yo ...
- 2018 CCPC网络赛
2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...
- 2018 CCPC网络赛 几道数学题
1002 Congruence equation 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6439 题解 : https://www.zyb ...
- 2018 CCPC网络赛 hdu6444 Neko's loop
题目描述: Neko has a loop of size n.The loop has a happy value ai on the i−th(0≤i≤n−1) grid. Neko likes ...
- 2018 CCPC 网络赛 Buy and Resell
The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1,2,…,n where allowed ...
- 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...
- 【2018 CCPC网络赛】1001 - 优先队列&贪心
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6438 获得最大的利润,将元素依次入栈,期中只要碰到比队顶元素大的,就吧队顶元素卖出去,答案加上他们期中 ...
- 【2018 CCPC网络赛】1009 - 树
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6446 题目给出的数据为一棵树,dfs扫描每条边,假设去掉某条边,则左边 x 个点,右边 n-x 个点, ...
- 【2018 CCPC网络赛】1003 - 费马小定理
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6440 这题主要是理解题意: 题意:定义一个加法和乘法,使得 (m+n)p = mp+np; 其中给定 ...
随机推荐
- bzoj 1982: [Spoj 2021]Moving Pebbles【博弈论】
必败状态是n为偶数并且数量相同的石子堆可以两两配对,因为这样后手可以模仿先手操作 其他状态一定可以由先手给后手一步拼出一个必败状态(用最大堆补) #include<iostream> #i ...
- 洛谷P2585 [ZJOI2006]三色二叉树(树形dp)
传送门 设$dp[u][i]$表示点$u$颜色为$i$时最多(最少)的绿点个数(这里用$0$表示绿点) 然后直接用树形dp就可以了 记得把情况讨论清楚 //minamoto #include<b ...
- Hexo瞎折腾系列(4) - 站点首页不显示文章全文
文章摘要设置 打开主题配置文件 _config.yml 文件,找到如下: # Automatically Excerpt. Not recommend. # Please use <!-- mo ...
- jquery html() 和text()的用法
html()类似JS中的 innerHTML,首先看一段代码: <!DOCTYPE html> <html lang="en"> <head> ...
- 利用lsof去查看Unix/Linux进程打开了哪些文件
利用lsof去查看Unix/Linux进程打开了哪些文件 今天用了一下lsof,发现这个linux的小工具,功能非常强大而且好用. 我们可以方便的用它查看应用程序进程打开了哪些文件或者对于特定的一个文 ...
- Centos 6.5安装MySQL-Python遇到的问题--解决办法一
系统:CentOS release 6.5 (Final) MySQL版本:mysql Ver 14.14 Distrib 5.7.19, for Linux (x86_64) using Edi ...
- Win7下单机版的伪分布式solrCloud环境搭建Tomcat+solr+zookeeper【转】
Win7下单机版的伪分布式solrCloud环境搭建Tomcat+solr+zookeeper 1.软件工具箱 在本文的实践中,需要用到以下的软件: Tomcat-7.0.62+solr-5.0.0+ ...
- 如何正确从他人机器MySQL数据库下拷贝出.sql,再导入到自己windows下MySQL数据库(图文详解)
不多说,直接上干货! 我这里,是放在桌面上. 登陆数据库 然后, mysql -uroot -p 默认是回车. 创建数据库 CREATE DATABASE securityonion_db; 目的,就 ...
- Jquary基础
基本知识: 就是一个JS函数包 选择器:基本选择器: 基本:ID选择器 “#” , Class选择器 “.”,标签选择器 “标签名” 组合:并列用“,”隔开 后代用空格隔开 过滤选择器:基本过滤: ...
- iOS之tableView性能优化/tableView滑动卡顿?
本文围绕以下几点展开tableView性能优化的论述? 1.UITableViewCell重用机制? 2.tableView滑动为什么会卡顿? 3.优化方法? 4.总结 1.UITableViewCe ...