HDU 4143 A Simple Problem
2012-09-12 17:13
393 查看
HDU 4143 A Simple Problem
http://acm.hdu.edu.cn/showproblem.php?pid=4143
两个for枚举肯定超时,移项因式分解后,只要一个for枚举(y-x)就好了,(y+x)用n去除(y-x)。
另外两个小点,关注到(y-x)一定小于等于sqrt(n),并且(y-x)与(y+x)不相等
http://acm.hdu.edu.cn/showproblem.php?pid=4143
两个for枚举肯定超时,移项因式分解后,只要一个for枚举(y-x)就好了,(y+x)用n去除(y-x)。
另外两个小点,关注到(y-x)一定小于等于sqrt(n),并且(y-x)与(y+x)不相等
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #define ll long long using namespace std; int work(int n) { int i,j,k,x,y,f=0; k=(int)sqrt(n); for(x=k;x>=1;x--) { if(n%x==0&&(x!=n/x)&&(n/x-x)%2==0) { f=1;break; } } if(f==0) return -1; else return (n/x-x)/2; } int main() { int t,i,j,n,m; scanf("%d",&t); while(t--) { scanf("%d",&n); m=work(n); printf("%d\n",m); } return 0; }
相关文章推荐
- hdu 4143 A Simple Problem
- HDU 4143 A Simple Problem(枚举)
- HDU 4143 A Simple Problem
- hdu 4143 A Simple Problem
- HDU 4143 A Simple Problem
- HDU 4143 A Simple Problem
- HDU 4143 A Simple Problem(数论-水题)
- HDU-4143 A Simple Problem
- HDU 4143 A Simple Problem(数论-水题)
- hdu 4143 A Simple Problem(数学)
- HDU 4143 A Simple Problem
- HDU 4143 A Simple Problem (枚举暴力)
- hdu 4975 A simple Gaussian elimination problem.(网络流 + 判多解)
- hdu 1757 A Simple Math Problem 矩阵基础题
- 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers
- hdu 4267 A Simple Problem with Integers
- HDU 4974 A simple water problem 模拟(水
- HDU 4973 A simple simulation problem. 线段树
- HDU - 4974 A simple water problem
- HDU 4971 A simple brute force problem.(最小割,最大权闭合图)