Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

给定一个直角三角形的一边长度。问是否存在一个直角三角形,使得它满足有一边的长度是x

当x=1、2的时候是无解的,可以暴力打表看看。

注意到,相邻的两个数的平方的差值是奇数

x^2 - (x-1)^2 = 2*x-1

间隔为2的两个数的平方的差值是偶数

(x+1)^2 - (x-1)^2 = 4*x

这样就可以分类讨论了。

把n永远当成是指角边就OK

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>

void work ()
{
    LL n;
    cin>>n;
    if (n==1 || n==2 )
    {
        cout<<-1<<endl;
        return ;
    }
    LL t = n*n;
    if (t&1)
    {
        LL k = (n*n+1)>>1;
        cout<<k<<" "<<k-1<<endl;
    }
    else
    {
        LL k = t>>2;
        cout<<k+1<<" "<<k-1<<endl;
    }
}
int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    work();
    return 0;
}

时间: 2024-10-07 02:45:04

Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学的相关文章

Codeforces Round #368 (Div. 2) Brain&#39;s Photos

Brain's Photos Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos

暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

题目传送门 1 /* 2 暴力:O (n^2) 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 #include <vector> 9 using namespace std; 10 11 const int MAXN = 1e4 + 10; 12 const int INF = 0x3f3f3f3f; 13 14

Codeforces Round #368 (Div. 2) Pythagorean Triples

Pythagorean Triples Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths

Codeforces 707 C. Pythagorean Triples(找规律)——Codeforces Round #368 (Div. 2)

传送门 Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding t

Codeforces Round #368 (Div. 2)

A. Brain's Photos 题意: 给你一个n*m的字符矩阵,如果字符中出现'C', 'M', 'Y'这三个中的任何一个就输出"#Color";否则输出"#Black&White". 代码如下: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <fstream> 5 #include <ctime&

Codeforces Round #368 (Div. 2) ABCD

A. Brain's Photos 题解: 水得不要不要的 代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)

Codeforces Round #368 (Div. 2) C

Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresp

Codeforces Round #368 (Div. 2) Bakery

Bakery Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply

Codeforces Round #368 (Div. 2) A

Description Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are