結果

問題 No.2392 二平方和
ユーザー pote-bokkopote-bokko
提出日時 2023-07-30 16:32:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,703 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 168,736 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 17:36:46
合計ジャッジ時間 2,312 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// STLのインクルード
#include <bits/stdc++.h>
using namespace std;

// // ACLのインクルード(デフォルトはコメントアウト)
// #include <atcoder/all>
// using namespace atcoder;

// for文の略記
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)

// vectorのソート
#define all(x) x.begin(), x.end()

// 型の略記 (競プロならでは)
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<long long, long long>>;
using vpsi = vector<pair<string, int>>;
using vvi = vector<vector<int>>;
using vvpii = vector<vector<pair<int, int>>>;
using vvl = vector<vector<long long>>;
using vvc = vector<vector<char>>;

// MOD計算で使う
#define MOD 1000000007
#define MOD2 998244353

// YES-NOで答える質問で使う(fがTrueならYes)
void cout_yn(bool f){
    if(f)cout << "Yes" << endl;
    else cout << "No" << endl;
}

// 木の前順走査
void dfs_preorder(int v, vvi &tree, vi &output){
    output.push_back(v);
    rep(i, tree[v].size()){
        dfs_preorder(tree[v][i], tree, output);
    }
}
// 木の後順走査
void dfs_postorder(int v, vvi &tree, vi &output){
    rep(i, tree[v].size()){
        dfs_preorder(tree[v][i], tree, output);
    }
    output.push_back(v);
}

// n頂点m辺の無向グラフを隣接リストで受け取る.
// 頂点番号は1-indexedとして入力される想定.
vector<vector<int>> input_undir_graph(int n, int m){
    int a, b;
    vector<vector<int>> g(n);
    rep(i, m){
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b); // a->b へ向かう辺
        g[b].push_back(a); // b->a へ向かう辺
    }
    return g;
}

// n頂点m辺の有向グラフを隣接リストで受け取る.
// 頂点番号は1-indexedとして入力される想定.
vector<vector<int>> input_dir_graph(int n, int m){
    int a, b;
    vector<vector<int>> g(n);
    rep(i, m){
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b); // a->b へ向かう辺
    }
    return g;
}

// main関数
int main(void){
    ll p;
    cin >> p;
    for(ll i=1; i*i <= p; i++){
        ll jj = p-i*i;
        ll j = sqrt(jj);
        if((j-1)*(j-1) == jj){
            cout << "Yes" << endl;
            return 0;
        }
        if(j*j == jj){
            cout << "Yes" << endl;
            return 0;
        }
        if((j+1)*(j+1) == jj){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


0