【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 个点, ...
随机推荐
- Java中使用MongoUtils对mongodb数据库进行增、删、查、改
本文主要介绍在java应用中如何使用MongoUtils工具类对 mongodb进行增.删.查.改操作. 一.配置 1.将 common.jar库引入到项目环境中: (源代码:https://gite ...
- 从零开始的全栈工程师——JS面向对象(复习)
作用域 栈内存:js执行的环境堆内存:存放代码块的空间 存放方式 键值对形式存放 字符串的形式存放js在执行之前 浏览器会给他一个全局作用域叫window 每个作用域下都分为两个模块 一个是内存模块一 ...
- vue授权页面登陆之后返回之前的页面
import Vue from 'vue'import Router from 'vue-router'Vue.use(Router)import home from "@/pages/ho ...
- CentOS安装QQ2012
QQ想必大家都会用,在windows系统下一般都是使用客户端软件,但是在linxu系统下就没有想windows那样的客户端了.下面就次啊用wine在CentOS中安装腾讯QQ2012.
- 【Linux】应用程序内存段布局
一.各段内存布局 内存布局图 1.BSS段(Block Started by Symbol)未初始化段 2.linux ELF base address is 0x8048000 应用程序虚拟地址起始 ...
- 多线程(三)~多线程中数据的可见性-volatile关键字
我们先来看一段代码: ①.线程类,用全局布尔值控制线程是否结束,每隔1s打印一次当前线程的信息 package com.multiThread.thread; publicclassPrintStri ...
- java面试题之----HashMap常见面试题总结
“你用过HashMap吗?” “什么是HashMap?你为什么用到它?” 几乎每个人都会回答“是的”,然后回答HashMap的一些特性,譬如HashMap可以接受null键值和值,而Hashtable ...
- supervisor运行virtualenv环境下的nagios-api
supervisord-example.conf [unix_http_server] file=/tmp/supervisor.sock ; path to your socket file [su ...
- day2-基础 变量,判断,循环
1.第一个程序 print ("Hello World!") 输出: 1 Hello World 2.第一个变量 a = ( print (a) 输出: Hello World 3 ...
- zip4j之加压解压
最近看同事搞个文件打包,搞了大半天,还是有问题!嗨~~ 网上明明有现成的,偏偏要自己写! 下面是基于zip4j实现加压解决的简单工具类 package com.learcher.zip; import ...