結果

問題 No.2392 二平方和
ユーザー rubish4garbagerubish4garbage
提出日時 2023-07-28 21:29:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 483 ms / 2,000 ms
コード長 6,856 bytes
コンパイル時間 1,098 ms
コンパイル使用メモリ 99,004 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-10-06 17:40:41
合計ジャッジ時間 3,755 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
12,916 KB
testcase_01 AC 34 ms
12,928 KB
testcase_02 AC 34 ms
13,056 KB
testcase_03 AC 35 ms
13,040 KB
testcase_04 AC 34 ms
12,928 KB
testcase_05 AC 35 ms
12,928 KB
testcase_06 AC 34 ms
13,056 KB
testcase_07 AC 36 ms
12,972 KB
testcase_08 AC 36 ms
12,884 KB
testcase_09 AC 35 ms
12,800 KB
testcase_10 AC 35 ms
12,912 KB
testcase_11 AC 35 ms
13,012 KB
testcase_12 AC 35 ms
12,928 KB
testcase_13 AC 35 ms
13,056 KB
testcase_14 AC 35 ms
12,916 KB
testcase_15 AC 35 ms
12,716 KB
testcase_16 AC 35 ms
12,800 KB
testcase_17 AC 37 ms
12,872 KB
testcase_18 AC 35 ms
12,892 KB
testcase_19 AC 35 ms
12,700 KB
testcase_20 AC 36 ms
12,756 KB
testcase_21 AC 444 ms
13,184 KB
testcase_22 AC 36 ms
12,844 KB
testcase_23 AC 35 ms
13,056 KB
testcase_24 AC 483 ms
12,928 KB
testcase_25 AC 35 ms
12,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string>
#include <iomanip>

using namespace std;

#define N 5005
#define M 200005
#define mod 998244353
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
#define endl '\n'
#define PII pair<int,int>
#define lr now<<1|1
#define rr (lr)+1
#define mid ((l+r)>>1)
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pi acos(-1)

class fastIO {
private:
    char ibuf[50007], *p1 = ibuf, *p2 = ibuf, obuf[50007], *p3 = obuf, sta[50];
    bool file_end = false;
    char get() {
        return p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 50007, stdin), p1 == p2) ? (file_end = true), char(EOF): *p1++;
    }
    void put(const char x) {
        p3 - obuf < 50007 ? *p3 ++ = x : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3++ = x);
    }
public:
    explicit operator bool() { return !file_end; }
    size_t flush() {
        size_t f = fwrite(obuf, p3 - obuf, 1, stdout);
        p3 = obuf;
        *p3 = 0;
        return f;
    }
    fastIO &operator>>(char &t) {
        for (t = get(); !isgraph(t); t = get());
        return *this;
    }
    template<typename any>
    typename enable_if<is_same<any, char>::value, any>::type tpval() {
        char t;
        for (t = get(); !isgraph(t); t = get());
        return t;
    }
    fastIO &operator>>(char *t) {
        char c;
        for (c = get(); !isgraph(c); c = get());
        for (; isgraph(c); c = get())*t = c, t++;
        *t = 0;
        return *this;
    }
    fastIO &operator>>(string &t) {
        t.clear();
        char c;
        for (c = get(); !isgraph(c); c = get());
        for (; isgraph(c); c = get())t += c;
        return *this;
    }
    template<typename any>
    typename enable_if<is_same<any, string>::value, any>::type tpval() {
        string t;
        char c;
        for (c = get(); !isgraph(c); c = get());
        for (; isgraph(c); c = get())t += c;
        return t;
    }
    template<typename any>
    typename enable_if<
    (is_signed<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
    is_same<any, __int128_t>::value, fastIO>::type &operator>>(any &t) {
        t = 0;
        bool y = 0;
        char c = get();
        for (; !isdigit(c); c = get())if (c == 45)y = true;
        for (; isdigit(c); c = get())t = t * 10 + c - 48;
        if (y == 1)t = -t;
        return *this;
    }
    template<typename any>
    typename enable_if<
    (is_signed<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
    is_same<any, __int128_t>::value, any>::type tpval() {
        any t = 0;
        bool y = 0;
        char c = get();
        for (; !isdigit(c); c = get())if (c == 45)y = true;
        for (; isdigit(c); c = get())t = t * 10 + c - 48;
        if (y == 1)t = -t;
        return t;
    }
    template<typename any>
    typename enable_if<
    (is_unsigned<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
    is_same<any, __uint128_t>::value, fastIO>::type &operator>>(any &t) {
        t = 0;
        char c = get();
        for (; !isdigit(c); c = get());
        for (; isdigit(c); c = get())t = t * 10 + c - 48;
        return *this;
    }
    template<typename any>
    typename enable_if<
    (is_unsigned<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
    is_same<any, __uint128_t>::value, any>::type tpval() {
        any t = 0;
        char c = get();
        for (; !isdigit(c); c = get());
        for (; isdigit(c); c = get())t = t * 10 + c - 48;
        return t;
    }
    template<typename any1, typename any2>
    fastIO &operator>>(pair<any1, any2> &t) { return *this >> t.first >> t.second; }
    template<typename any1, typename any2>
    pair<any1, any2> tpval() { return pair<any1, any2>(tpval<any1>(), tpval<any2>()); }
    template<typename any>
    fastIO &read(any &t) { return *this >> t; }
    fastIO &read(char *t) {
        char c;
        for (c = get(); !isgraph(c); c = get());
        for (; isgraph(c); c = get())*t = c, t++;
        *t = 0;
        return *this;
    }
    template<typename any, typename...args>
    fastIO &read(any &t1, args &...t2) { return (*this >> t1).read(t2...); }
    fastIO &operator<<(const char t) {
        put(t);
        return *this;
    }
    fastIO &operator<<(const char *t) {
        for (; *t; t++)put(*t);
        return *this;
    }
    fastIO &operator<<(const string &t) {
        for (const char it: t)put(it);
        return *this;
    }
    template<typename any>
    typename enable_if<
    (is_signed<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
    is_same<any, __int128_t>::value, fastIO>::type &operator<<(any t) {
        if (!t) {
            put(48);
            return *this;
        }
        int len = 0;
        if (t < 0)t = -t, put(45);
        while (t)sta[len++] = char(t % 10 + 48), t /= 10;
        while (len--)put(sta[len]);
        return *this;
    }
    template<typename any>
    typename enable_if<
    (is_unsigned<any>::value && is_integral<any>::value && !is_same<any, char>::value) ||
    is_same<any, __uint128_t>::value, fastIO>::type &operator<<(any t) {
        if (!t) {
            put(48);
            return *this;
        }
        int len = 0;
        while (t)sta[len++] = char(t % 10 + 48), t /= 10;
        while (len--)put(sta[len]);
        return *this;
    }
    template<typename any1, typename any2>
    fastIO &operator<<(const pair<any1, any2> &t) { return *this << t.first << ' ' << t.second; }
    template<typename any>
    fastIO &write(const any &t) { return *this << t; }
    template<typename any, typename...args>
    fastIO &write(const any &t1, const args &...t2) { return (*this << t1).write(t2...); }
    
    ~fastIO() { fwrite(obuf, p3 - obuf, 1, stdout); }
}FastIO;
#ifdef ONLINE_JUDGE
#define cin FastIO
#define cout FastIO
#endif
int pri[1000010],idx;
bool st[1000010];
int phi[1000010];

void get_prime()
{
    phi[1]=1;
    for (int i=2; i<=1000000; i++) {
        if(!st[i])
        {
            pri[idx++]=i;
            phi[i]=i-1;
        }
        for (int j=0; i<=1000000/pri[j]; j++) {
            st[i*pri[j]]=true;
            if(i%pri[j]==0)
            {
                phi[i*pri[j]]=pri[j]*phi[i];
                break;
            }
            phi[i*pri[j]]=(pri[j]-1)*phi[i];
        }
    }
}
void solve()
{
    int p;
    cin>>p;
    for (int i=1; i<=p/2; i++) {
        int x=p-i*i;
        int y=sqrt(x);
        if(y*y==x)
        {
            cout<<"Yes"<<endl;
            return;
        }
    }
    cout<<"No"<<endl;
}

signed main()
{
    get_prime();
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

0