【2018 CCPC网络赛 1004】Find Integer(勾股数+费马大定理)
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
Sample Output
4 5
题意:
本题是Special Judge,共有T组数据,每组数据给出n和a,让我们找到一个符合an+bn=cn的b和c,若不存在输出-1 -1。
思路:
(1) 根据费马大定理可知:当整数n >2时,关于a, b, c的方程 a^n + b^n = c^n 没有正整数解,所以只需讨论n≤2的情况。
(2) 当n=0时,会得到等式1+1=1,显然不可能。
(3) 当n=1时,会得到等式a+b=c,输出符合条件的数据即可。
(4) 当n=2时:
<1> 当a>=3且a=2*x+1(a为奇数,x为正整数)时,b=2x2+2x,c=2x2+2x+1。
<2> 当a>4且a=2*x(a为偶数,x为正整数)时,b=x2-1,c=x2+1。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,a,x;
cin>>t;
while(t--)
{
scanf("%d%d",&n,&a);
if(n==)
printf("%d %d\n",,a+);
else if(n>||!n)
printf("-1 -1\n");
else
{
if(a%==)
{
x=(a-)/;
printf("%d %d\n",*x*x+*x,*x*x+*x+);
}
else if(a%==)
{
x=a/;
printf("%d %d\n",x*x-,x*x+);
}
}
}
return ;
}
【2018 CCPC网络赛 1004】Find Integer(勾股数+费马大定理)的更多相关文章
- 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网络赛】1004 - 费马大定理&数学
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Knowledge Point: 1. 费马大定理:当整数n >2时,关于x, y, z的 ...
- 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 网络赛
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 个点, ...
随机推荐
- springboot从入门到精通(二)
这一节我们一起用springboot开发一个应用程序,应用程序里的核心概念是玩家获取英雄列表上的英雄信息. 1.定义实体模型: 代码如下: package com.dota.herolist.enti ...
- MyBatis 中 sqlmapconfig核心标签说明以及配置
文件介绍 对于 MyBatis 最核心的全局配置文件是 sqlmapConfig.xml 文件,其中包含了数据库的连接配置信息.Mapper 映射文件的加载路径.全局参数.类型别名等. 配置项详解 标 ...
- 归并排序——Java实现
一.排序思想 将两个或两个以上的一排序文件合并成一个有序文件的过程叫归并,而归并排序就是建立在归并操作上的一种有效的排序算法,该算法是采用分治法的一个非常典型的应用.将以有序的了序列合并,得到完全有序 ...
- Csharp: TreeView 初始化设置默认选择节点
/// <summary> /// 设置查找的节点为选定节点 /// 涂聚文 /// 2013-07-15 /// </summary> /// <param name= ...
- centos7 版本防火墻操作和配置
1.关闭firewall:systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止fire ...
- javascript接入阿里云服务器
authInfo = r.data.authInfo[0]//后台请求的 var client = new OSS({ region: 'oss-cn-beijing',// 云账号AccessKey ...
- 从软件工程师的角度看MacBook Air的几个设计亮点
我多年从事软件开发和运营工作,从未跟“设计”间断过.现在在设计一个全新saas产品:超级表格(www.domypp.com).最近买了台苹果最新款的笔记本电脑MacBook Air,从该产品功能设计和 ...
- Android上使用RecyclerView实现顶部悬浮标题效果的Sticky Title View
目前很多的项目都在使用顶部悬浮标题的效果,很明显,这的确是一个比较人性化,用户体验效果比较好的UI交互效果,对于这个效果,有很多种实现方式,如果说要用RecyclerView来实现一个分类信息展示,并 ...
- Set up ruby debugging environment
Today I finally got ruby debugging working in Eclipse. Below are the major setup steps involved, as ...
- 如何开放 Azure 虚拟机 Ping 功能
前言 文章<使用 PsPing & PaPing 进行 TCP 端口连通性测试>中提到,ICMP 协议的数据包无法通过 Azure 的防火墙和负载均衡器,所以不能直接使用 Ping ...