結果

問題 No.1653 Squarefree
ユーザー milanis48663220milanis48663220
提出日時 2021-08-20 22:44:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 2,256 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 126,924 KB
実行使用メモリ 11,608 KB
最終ジャッジ日時 2024-04-22 09:12:17
合計ジャッジ時間 7,338 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
11,484 KB
testcase_01 AC 11 ms
5,248 KB
testcase_02 AC 11 ms
5,376 KB
testcase_03 AC 12 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 12 ms
5,376 KB
testcase_06 AC 11 ms
5,376 KB
testcase_07 AC 11 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 12 ms
5,376 KB
testcase_10 AC 12 ms
5,376 KB
testcase_11 AC 175 ms
11,604 KB
testcase_12 AC 171 ms
11,608 KB
testcase_13 AC 182 ms
11,500 KB
testcase_14 AC 184 ms
11,480 KB
testcase_15 AC 186 ms
11,536 KB
testcase_16 AC 183 ms
11,608 KB
testcase_17 AC 180 ms
11,604 KB
testcase_18 AC 181 ms
11,572 KB
testcase_19 AC 181 ms
11,604 KB
testcase_20 AC 179 ms
11,608 KB
testcase_21 AC 180 ms
11,536 KB
testcase_22 AC 191 ms
11,600 KB
testcase_23 AC 183 ms
11,480 KB
testcase_24 AC 177 ms
11,552 KB
testcase_25 AC 187 ms
11,608 KB
testcase_26 AC 185 ms
11,480 KB
testcase_27 AC 187 ms
11,592 KB
testcase_28 AC 188 ms
11,476 KB
testcase_29 AC 185 ms
11,608 KB
testcase_30 AC 178 ms
11,480 KB
testcase_31 AC 186 ms
11,576 KB
testcase_32 AC 201 ms
11,608 KB
testcase_33 AC 193 ms
11,608 KB
testcase_34 AC 178 ms
11,608 KB
testcase_35 AC 188 ms
11,608 KB
testcase_36 AC 12 ms
5,376 KB
testcase_37 AC 12 ms
5,376 KB
testcase_38 AC 12 ms
5,376 KB
testcase_39 AC 11 ms
5,376 KB
testcase_40 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

class Eratosthenes{
    public:
    int m;
    vector<bool> is_prime;
    vector<int> primes;
    Eratosthenes(int m_){
        m = m_;
        init();
    }
    private:
    void init(){
        is_prime.assign(m+1, true);
        is_prime[0] = false, is_prime[1] = false;
        for(int i = 2; i <= m; i++){
            if(is_prime[i]){
                primes.push_back(i);
                for(int j = 2; i*j <= m; j++) is_prime[i*j] = false;
            }
        }
    }
};


// calc a//b 
template<typename T>
T ceil_div(T a, T b){
    return (a+b-1)/b;
}

ll sqrt_ll(ll x){
    ll ans = sqrt(x)+0.1;
    if(ans*ans > x) ans--;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    auto erat = Eratosthenes(1000001);
    ll l, r; cin >> l >> r;
    int n = r-l+1;
    vector<bool> square_free(n, true);
    vector<ll> val(n);
    for(int i = 0; i < n; i++) val[i] = l+i;
    for(ll p : erat.primes){
        ll x = ceil_div(l, p);
        for(ll y = x*p; y <= r; y += p){
            int idx = y-l;
            // debug_value(y)
            if(val[idx]%(p*p) == 0){
                square_free[idx] = false;
            }
            while(val[idx]%p == 0) val[idx] /= p;
        }
    }
    int ans = 0;
    for(ll x = l; x <= r; x++){
        int idx = x-l;
        if(!square_free[idx]) continue;
        ll sq = sqrt_ll(val[idx]);
        // cout << val[idx] << endl;
        if(sq > 1000000 && sq*sq == val[idx]) continue;
        ans++;
    }
    ll x = 1e15;
    // cout << x-1000000 << ' ' << x << endl;
    cout << ans << endl;
}
0