题目地址: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. $.ajax与$.post、$.get的一点区别

    后台代码: [HttpPost] public string DoLogin(string username,string password) { return "success" ...

  2. ASP.NET Core 依赖注入(DI)

    ASP.NET Core的底层设计支持和使用依赖注入.ASP.NET Core 应用程序可以利用内置的框架服务将服务注入到启动类的方法中,并且应用程序服务也可以配置注入.由ASP.NET Core 提 ...

  3. python __builtins__ map类 (44)

    44.'map',  根据提供的函数对指定序列做映射. class map(object) | map(func, *iterables) --> map object | | Make an ...

  4. 如何修改hosts文件并生效

    hosts文件位置C:\Windows\System32\drivers\etc(可以建立一个.bat 的文件把(start "" C:\Windows\System32\driv ...

  5. 2019 年 Vue 学习路线图!

    如果你是 Vue 开发新手,可能已经听过很多行话术语,比如单页面应用程序.异步组件.服务器端渲染,等等.你可能还听说过与 Vue 有关的一些工具和库,比如 Vuex.Webpack.Vue CLI 和 ...

  6. GCD = XOR(GCD XOR )

    首先没看懂XOR(于是百度了一下):异或,英文为exclusive OR,或缩写成xor.同时还有一个OR,于是一起看了一眼: 大意: 输入一个整数n,在1~n内,有多少对整数(a,b)满足GCD(a ...

  7. ARC 100

    链接 https://arc100.contest.atcoder.jp/ C Linear Approximation 题解 把ai减去i后排序, 我们要的b就是排完序后的中位数 Code #inc ...

  8. PopupWindow(3)back,home 键无法关闭popupwindow的解决方案

    private PopupWindow mPopupWindow; //popup window 一般popuowindow 要都个显示view,本例子中view模拟菜单. private View ...

  9. 18.3.2从Class上获取信息(构造器)

    获取构造器信息 package d18_3_1; import java.lang.reflect.Constructor; import java.util.Arrays; /** * 获取构造器的 ...

  10. 转--oracle查看允许的最大连接数和当前连接数等信息

    两个参数间的关系:sessions=1.1*processes+5 目前总结的语句,在查看数据的连接情况很有用,写完程序一边测试代码一边查看数据库连接的释放情况有助于分析优化出一个健壮的系统程序来. ...