• CodeForces 707C Pythagorean Triples (数论)


    题意:给定一个数n,问你其他两边,能够组成直角三角形。

    析:这是一个数论题。

    如果 n 是奇数,那么那两边就是 (n*n-1)/2 和 (n*n+1)/2。

    如果 n 是偶数,那么那两边就是 (n/2*n/2-1) 和 (n/2*n/2+1)。
    那么剩下的就很简单了。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #define frer freopen("in.txt", "r", stdin)
    #define frew freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 8;
    const int mod = 1e9 + 7;
    const char *mark = "+-*";
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    inline LL Min(LL a, LL b){ return a < b ? a : b; }
    inline LL Max(LL a, LL b){ return a > b ? a : b; }
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    int main(){
        LL x;
        while(cin >> x){
            if(x < 3){ printf("-1
    ");  continue; }
    
            if(x & 1)  printf("%I64d %I64d
    ", (x*x-1)/2, (x*x+1)/2);
            else{
                x /= 2;
                printf("%I64d %I64d
    ", x*x-1, x*x+1);
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    python3全栈开发-并发编程的多进程理论
    python3全栈开发-补充UDP的套接字、操作系统、并发的理论基础
    python3全栈开发-什么是粘包、粘包现象、如何解决粘包
    python3全栈开发-socket编程
    python3全栈开发- 元类metaclass(面试必考题)
    浏览器窗口
    SQL 笔记
    数据库连接字符串
    获取网卡地址信息
    启动所选择的应用程序
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5793179.html
Copyright © 2020-2023  润新知