結果

問題 No.3156 Count That Day's N
ユーザー Cafe1942
提出日時 2025-05-23 19:21:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 114 ms / 3,000 ms
コード長 1,531 bytes
コンパイル時間 1,322 ms
コンパイル使用メモリ 114,756 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-23 19:21:25
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
using ll = long long;
using namespace std;
#define modP7 1'000'000'007
#define modP 998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }

int squareRoot(long long x) {
    int left = 1;
    int right = (int)1e8;
    int mid;
    while (right - left > 1) {
        mid = (right + left) / 2;
        if ((long long)mid * (long long)mid <= x) {
            left = mid;
        }
        else {
            right = mid;
        }
    }
    return left;
}

int main() {
    ll K;
    cin >> K;
    ll N;
    cin >> N;
    ll X[317];
    ll Y[5624];
    for (ll x = 1;x <= 316;x++) {
        X[x] = x * x * x * x * x * x;
    }
    for (ll y = 1;y <= 5623;y++) {
        Y[y] = y * y * y * y;
    }
    unordered_set <ll>ans;
    for (int i = 1;i <= 316;i++) {
        if (N < X[i])break;
        for (int j = 1;j <= 5623;j++) {
            if (N < X[i] + Y[j])break;
            if ((X[i] + Y[j]) % K == 0) {
                if ((ll)squareRoot((X[i] + Y[j]) / K) * (ll)squareRoot((X[i] + Y[j]) / K) == (X[i] + Y[j]) / K) {
                    ans.insert(X[i] + Y[j]);
                }
            }
        }
    }
    cout << ans.size();
    return 0;
}
0