【题目链接】:http://codeforces.com/contest/707/problem/C

【题意】



给你一个数字n;

问你这个数字是不是某个三角形的一条边;

如果是让你输出另外两条边的大小;

【题解】



首先明确n<=2的时候是无解的。

n>2之后都有解;

这里设

n2+b2=a2

则有

n2=a2−b2

也即

n2=(a+b)∗(a−b)

这里对n分两类讨论;



n为奇数

则令

a−b=1

a+b=n2

这样

2∗a=n2+1

因为n是奇数所以右边是个偶数;

得出来的a就是整数了符合题意;

然后b=a-1



n为偶数

则令

a−b=2

a+b=n2/2



2∗a=n2/2+2

a=n2/4+1

因为n是大于2的偶数,所以a最后得到的结果是个整数且大于2;

b=a-2;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110; LL n;
LL sqr(LL x) { return x*x; } int main(){
//freopen("F:\\rush.txt", "r", stdin);
rel(n);
if (n <= 2) return puts("-1"), 0;
if (n & 1)
{
LL b = (sqr(n) + 1) / 2;
LL a = b - 1;
printf("%lld %lld\n", a, b);
}
else
{
LL b = sqr(n) / 4 + 1;
LL a = b - 2;
printf("%lld %lld\n", a, b);
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

最新文章

  1. SOUI与WTL
  2. FMS直播流发布时 Microphone Speex 编码设置注意事项
  3. bzoj 1305: [CQOI2009]dance 二分+網絡流判定
  4. javascript 获取滚动条高度+常用js页面宽度与高度(转)
  5. 跨平台生成GUID/UUID
  6. [置顶] Objective-C ,ios,iphone开发基础:UIAlertView使用详解
  7. 学习笔记TF011:多层神经网络
  8. fatal error LNK1201:写入程序数据库“***.pdb”时出错;请检查是否是磁盘空间不足、路径无效或权限不够
  9. C#扩展方法类库StringExtensions
  10. 解决Cell重用内容混乱的几种简单方法,有些方法会增加内存
  11. Axis创建webservice客户端和服务端
  12. Django 项目创建之前的环境搭建
  13. /usr/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.2.1) doesn&#39;t match a supported version! RequestsDependencyWarning)
  14. Linux 默认连接数
  15. VNPY 软件架构分析
  16. sixsix团队“餐站”应用代码规范及开发文档
  17. android: 使用本地广播
  18. CentOS环境PHP安装memcache扩展
  19. (弃) Keystone CLI_选项与子命令概况
  20. godaddy nginx https 配置

热门文章

  1. JSP页面结构
  2. bzoj 1594: [Usaco2008 Jan]猜数游戏【二分+线段树】
  3. (前缀和 内存分配)51NOD 1081 子段求和
  4. Java多线程(三)SimpleDateFormat
  5. [AHOI2006] 文本编辑器editor
  6. python 模块-easygui.buttonbox
  7. 如何利用CSS中的ime-mode用来控制页面上文本框中的全角/半角输入
  8. linux下启动、停止tomcat,杀死tomcat进程
  9. Spring scheduled cron 表达式
  10. Android Measure 体系简单总结