题目链接:
https://codeforces.com/contest/707/problem/C
题目:
题意:
告诉你直角三角形的一条边,要你输出另外两条边。
思路:
我们容易发现除2外的所有素数x作为直角边,那么另外两条边的长度一定为(x * x - 1)/2和(x * x + 1)/2,因此对于每个数我们只需要找到n的最小素因子(除2外)即可,需要额外处理一下2的幂次。
代码实现如下:
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-;
const int mod = ;
const int maxn = 2e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; LL t; int main(){
scanf("%lld", &t);
if(t <= ) {
puts("-1");
return ;
}
for(int i = ; i <= sqrt(t); i++) {
if(t % i == ) {
LL tmp = t / i;
LL x = 1LL * i * i;
if(x & ) {
printf("%lld %lld\n", (1LL * i * i - ) / * tmp, (1LL * i * i + ) / * tmp);
return ;
}
}
}
LL num = ;
while(t % == ) {
num = num * ;
t /= ;
}
if(t == ) {
t = ;
num /= ;
printf("%lld %lld\n", * num, * num);
} else {
printf("%lld %lld\n", (t * t - ) / * num, (t * t + ) / * num);
}
return ;
}