博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU-4143 A Simple Problem
阅读量:6950 次
发布时间:2019-06-27

本文共 1299 字,大约阅读时间需要 4 分钟。

A Simple Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

Total Submission(s): 1959    Accepted Submission(s): 518

Problem Description
For a given positive integer n, please find the smallest positive integer x that we can find an integer y such that y^2 = n +x^2.
 

 

Input
The first line is an integer T, which is the the number of cases.
Then T line followed each containing an integer n (1<=n <= 10^9).
 

 

Output
For each integer n, please print output the x in a single line, if x does not exit , print -1 instead.
 

 

Sample Input
2 2 3
 

 

Sample Output
-1 1
 
/*解题思路:给定n,求最小的x使其满足 y^2 = n +x^2 ,分解因式可得(y-x)*(y+x)=n,枚举y-x即可,注意y-x一定小于y+x;*///代码一:#include
int main(){ int T,i,a,n,tmp,ans; scanf("%d",&T); while(T--) { ans=0x7fffffff; scanf("%d",&n); for(i=1;i*i
>1; if(tmp
#include
int main() { int T,i,flag,n; scanf("%d",&T); while(T--) { flag=0; scanf("%d",&n); for(i=sqrt(n);i>=1;--i) { if(n%i==0&&(n/i-i)%2==0&&n/i!=i) { flag=1; break; } } if(flag) printf("%d\n",(n/i-i)/2); else printf("-1\n"); } return 0;}*/

  

转载地址:http://hkuil.baihongyu.com/

你可能感兴趣的文章
supervisor进程管理工具
查看>>
自定义toast实现
查看>>
shell脚本备份数据库
查看>>
解决ant编译中出现“includeantruntime was not set”警告的问题
查看>>
常用html元素的取值和赋值方法总结
查看>>
分析一个闭包函数
查看>>
Nginx的静态文件合并请求,加快网站的加载速度
查看>>
linux底层内存管理--内核空间的伙伴系统
查看>>
CentOS7安装配置svn及svn hook实战
查看>>
Unit 11 电话转接
查看>>
比特币创业公司Circle首获数字货币许可证
查看>>
DHCP中继数据包互联网周游记
查看>>
一个简单的基于postfix+extmail+mysql的邮件系统
查看>>
访问控制模型DAC,MAC,RBAC
查看>>
查询优化器内核剖析第一篇
查看>>
网络应用瑞士军刀——Zentyal(4 常用命令)
查看>>
iOS开发技巧:使用Objective-C创建UUID
查看>>
如何在WP模拟器中启动、暂停、重启应用
查看>>
System Security Services Daemon(SSSD)系统安全服务守护进程
查看>>
渗透场景篇--当XSS遇上CSRF
查看>>