結果

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

ソースコード

diff #

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define YES YESNO(true)
#define NO YESNO(false)
#define REV_PRIORITY_QUEUE(tp) priority_queue<tp,vector<tp>,greater<tp>>
#define EXIT_ANS(x) {cout << (x) << '\n'; return;}
template <typename T> void inline SORT(vector<T> &v){sort(v.begin(),v.end()); return;}
template <typename T> void inline VEC_UNIQ(vector<T> &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return;}
template <typename T> T inline MAX(vector<T> &v){return *max_element(v.begin(),v.end());}
template <typename T> T inline MIN(vector<T> &v){return *min_element(v.begin(),v.end());}
template <typename T> T inline SUM(vector<T> &v){T ans = 0; for(int i = 0; i < (int)v.size(); i++)ans += v[i]; return ans;}
template <typename T> void inline DEC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]--; return;}
template <typename T> void inline INC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]++; return;}
void inline TEST(void){cerr << "TEST" << endl; return;}
template <typename T> bool inline chmin(T &x,T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}
template <typename T> bool inline chmax(T &x,T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template <typename T = long long> vector<T> inline get_vec(int n){
    vector<T> ans(n);
    for(int i = 0; i < n; i++)cin >> ans[i];
    return ans;
}
template <typename T> void inline print_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cout << vec[i];
        if(kaigyou || i == n - 1)cout << '\n';
        else cout << ' ';
    }
    if(!n)cout << '\n';
    return;
}
template <typename T> void inline debug_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cerr << vec[i];
        if(kaigyou || i == n - 1)cerr << '\n';
        else cerr << ' ';
    }
    if(!n)cerr << '\n';
    return;
}
vector<vector<int>> inline get_graph(int n,int m = -1,bool direct = false){
    if(m == -1)m = n - 1;
    vector<vector<int>> g(n);
    while(m--){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        if(!direct)g[v].push_back(u);
    }
    return g;
}

// floor(sqrt(x))を整数で返す。にぶたんしているが幅が定数なので計算時間はO(1) にぶたん内で重い動作もない(代入、掛け算、ビットシフト、大小比較だけ)
long long ococo_floor_lsqrt(long long x) {

    // この仕様で嬉しいか?
    if(x < 0) {
        return -1;
    }
    if(x < INT_MAX / 2) {
        int ix = x;
        if(x == 0) return 0;
        if(x < 4) return 1;
        if(x < 9) return 2;

        int l = std::sqrt((double)x) - 2, r = std::sqrt((double)x) + 2;
        for(int i = l; i <= r + 1; i++) {
            if(i * i > ix) return i - 1;
        }
        return r + 1;
    }
    // doubleの仮数部が52bitでlong longが64bitだから差が12bitのため、誤差が2**12=4096を超えないんじゃないかと思ってこの範囲でにぶたんをしているが、
    // 全然これは嘘かもしれないので、めちゃくちゃ要検証である。
    // 一旦±10で見てダメそうだったら5000広げる方向性にした。これ以上の高速化が必要なパターンはあんまないだろうしこれでええやろ
    // とりあえずこのにぶたんは、sqrt(x)の答えが[l,r]のどこかにあるものとしている
    long long l = std::sqrt((double)x) - 10, r = std::sqrt((double)x) + 10;
    if(l * l > x) l -= 5000;
    if(r * r < x) r += 5000;
    while(r - l >= 2) {
        long long c = (r + l) >> 1;
        if(c * c <= x) l = c;
        else r = c;
    }
    for(long long i = l; i <= r + 1; i++) {
        if(i * i > x) return i - 1;
    }
    return r + 1;
}


#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    //複数の解法のアイデアを思いついた時は全部メモしておく
    //g++ -D_GLIBCXX_DEBUG -Wall -O2 b.cpp -o o
    ll k,n;
    cin >> k >> n;
    vector<ll> v;
    for(ll x = 1; x * x * x * x* x * x <= n; x++){
        ll x6 = x * x * x * x* x * x ;
        for(ll y = 1; x6 + y * y * y * y <= n; y++){
            v.push_back(x6 + y * y * y * y);
        }
    }
    VEC_UNIQ(v);
    int ans = 0;
    for(int i = 0; i < (int)v.size(); i++){
        if(v[i] % k != 0)continue;
        v[i] /= k;
        ll sq = ococo_floor_lsqrt(v[i]);
        if(sq * sq == v[i])ans++;
    }
    cout << ans << el;
    return;
}

void calc(void){
    return;
}

signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0