zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    MQTT TLS 加密传输
    python多进程并发redis
    各种消息队列的特点
    mqtt异步publish方法
    Numpy API Analysis
    Karma install steps for unit test of Angular JS app
    reinstall bower command
    Simulate getter in JavaScript by valueOf and toString method
    How to: Raise and Consume Events
    获取对象的类型信息 (JavaScript)
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5793179.html
Copyright © 2011-2022 走看看