【Codeforces 707C】Pythagorean Triples

相关链接

题目传送门:http://codeforces.com/contest/707/problem/C

解题报告

这个题目第一眼看到,一脸懵逼,觉得这个东西一定是爆搜
后来想不出来弃疗了

今天再来看,也是没有思路,但看到了第三组样例,便一下子又了思路
假设我们读入a,考虑a^2+b^2=c^2,移相得a^2=(c+b)*(c-b)
如果a^2为奇数,让c-b=1即可
如果a^2为偶数,让c-b=2即可

Code

#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;

LL a,b,c;

int main(){
	cin>>a; a *= a;
	if (a <= 4) cout<<-1;
	else if (a & 1) cout<<a/2<<' '<<a/2+1;
	else cout<<a/4+1<<' '<<a/4-1;
	return 0;
} 

2 thoughts to “【Codeforces 707C】Pythagorean Triples”

  1. Thanks a lot for sharing this with all of us you actually know what you are talking about! Bookmarked. Please also visit my site =). We could have a link exchange contract between us!

  2. Howdy! I could have sworn I’ve been to this blog before but after checking through some of the post I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll be bookmarking and checking back often!

Leave a Reply

Your email address will not be published. Required fields are marked *