結果

問題 No.1218 Something Like a Theorem
ユーザー kyoskyos
提出日時 2020-09-04 22:51:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 164,560 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 20:30:04
合計ジャッジ時間 2,493 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int getpown(int a, int n)
{
    int ret = 1;
    rep(i, n) ret *= a;
    return ret;
}

// n乗がkになるものが存在するか
bool check(int k, int n, int z)
{
    int l = 1;
    int r = z;
    while( r > l + 1 )
    {
        int m = (l + r) / 2;
        int mn = getpown(m, n);
        if( mn == k ) return true;
        if( mn > k )
        {
            r = m;
        }
        else
        {
            l = m;
        }
    }
    int ln = getpown(l, n);
    return ln == k;
}

int main()
{
    int n, z; cin >> n >> z;
    int zn = getpown(z, n);
    rep(x, z)
    {
        if( x == 0 ) continue;
        int xn = getpown(x, n);
        if( check( zn - xn, n, z) )
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;    
}
0