题目地址: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 - 费马大定理&数学的更多相关文章

  1. 【2018 CCPC网络赛 1004】Find Integer(勾股数+费马大定理)

    Problem Description people in USSS love math very much, and there is a famous math problem . give yo ...

  2. 2018 CCPC网络赛

    2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...

  3. 2018 CCPC网络赛 几道数学题

    1002 Congruence equation 题目链接  : http://acm.hdu.edu.cn/showproblem.php?pid=6439 题解 : https://www.zyb ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 【2018 CCPC网络赛】1001 - 优先队列&贪心

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6438 获得最大的利润,将元素依次入栈,期中只要碰到比队顶元素大的,就吧队顶元素卖出去,答案加上他们期中 ...

  8. 【2018 CCPC网络赛】1009 - 树

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6446 题目给出的数据为一棵树,dfs扫描每条边,假设去掉某条边,则左边 x 个点,右边 n-x 个点, ...

  9. 【2018 CCPC网络赛】1003 - 费马小定理

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6440 这题主要是理解题意: 题意:定义一个加法和乘法,使得 (m+n)p = mp+np; 其中给定 ...

随机推荐

  1. git status -s 的表达式的读法

     1  2  读法  解决方案  ??    未被追踪  git add -A 或git add 文件路径  A    新添加文件 注:??被add后的状态  OK,等待commit.  M    已 ...

  2. Hello world——程序员的第一篇代码

    Hello world 是和A+B问题并驾齐驱的一道题,也是当世的经典题之一. 题目: 输出“Hello world”    样例输入 样例输出    Hello world Hello world ...

  3. Jmeter逻辑控制器操作,附栗子

    jmeter中的逻辑控制器确定采样器的执行顺序.右键线程组-->添加-->逻辑控制器. 一.简单控制器 简单控制器对JMeter如何处理添加到其中的采样器没有影响.只是方便我们做分组命名. ...

  4. python 蓝牙模块pybluz安装

    最近项目运用了蓝牙,所以来学一学蓝牙. 经过查阅,知道python的蓝牙模块是pybluz,然后老管理进行安装 出错,提示“Could not find the Windows Platform SD ...

  5. Jquery | 基础 | 慕课网 | 基本筛选选择器

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  6. 跟我一起玩Win32开发(10):绘图(C)

    今天我们来欣赏一下用于填充图形的函数,当然我不会逐个去介绍,因为我们参考MSDN直接套参数就可以了. SetDCBrushColor函数有必要扯一下,它的声明如下: COLORREF SetDCBru ...

  7. Hdu 5459 Jesus Is Here (2015 ACM/ICPC Asia Regional Shenyang Online) 递推

    题目链接: Hdu 5459 Jesus Is Here 题目描述: s1 = 'c', s2 = 'ff', s3 = s1 + s2; 问sn里面所有的字符c的距离是多少? 解题思路: 直觉告诉我 ...

  8. Codeforces Round #261 (Div. 2) E

    Description Pashmak's homework is a problem about graphs. Although he always tries to do his homewor ...

  9. 数组Reduce的应用

    数组Reduce的应用 参考 简单应用 var arr = [1,2,3,4,5] var sum = arr.reduce(function (prev, cur, index, arr) { co ...

  10. MySQL FailOver(官方自带,free)

    为什么 传统复制和GTIDs切换的缺点 当replication故障出现之后,最头疼是replication架构的调整 一旦master down了,就需要配置某一台slave作为master sla ...