結果

問題 No.1653 Squarefree
ユーザー milanis48663220milanis48663220
提出日時 2021-08-20 22:38:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,164 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 126,640 KB
実行使用メモリ 22,232 KB
最終ジャッジ日時 2024-04-22 05:28:34
合計ジャッジ時間 8,052 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

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){
        int x = ceil_div(l, p);
        for(ll y = x*p; y <= r; y += p){
            int idx = y-l;
            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++;
    }
    cout << ans << endl;
}
0