結果

問題 No.1653 Squarefree
ユーザー Focus_SashFocus_Sash
提出日時 2021-08-20 22:38:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,686 bytes
コンパイル時間 4,117 ms
コンパイル使用メモリ 264,192 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-10-14 04:43:39
合計ジャッジ時間 5,828 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using vl = vector<long long>;
using pl = pair<long long, long long>;
using PQ = priority_queue<long long>;
using PQR = priority_queue<long long, vector<long long>, greater<>>;
struct edge {long long to;long long cost;edge(long long t,long long c):to(t),cost(c){}};
using Graph = vector<vector<long long>>;
using WGraph = vector<vector<edge>>;
constexpr int dx[8]{1,0,-1,0,1,1,-1,-1};
constexpr int dy[8]{0,1,0,-1,1,-1,1,-1};
#define rep(i, n) for(long long (i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define pb emplace_back
#define V vector
#define uniquify(vec) sort(all(vec)); (vec).erase(std::unique((vec).begin(), (vec).end()), (vec).end())
constexpr long long MOD1 = 1e9 + 7;
constexpr long long MOD9 =  998244353;
constexpr long long INF = MOD1*MOD1+1;
constexpr long long LL_MAX = std::numeric_limits<long long>::max();
long long safe_mod(long long n, long long m){if(n >= 0) {return n % m;} else return (n%m + m)%m;}
long long div_ceil(long long a, long long b){return (a + b - 1) / b;}
long long DIG(long long x, long long d){ll ret=0;while(x){x/=d;ret++;}return ret;}
long long pw(long long x,long long n) {ll ret=1;while(n>0){if(n&1){ret=ret*x;}if(n>>=1){x=x*x;}}return ret;}
template<typename T> T SUM(const vector<T> &v){T ret{};return(accumulate(all(v), ret));}
template<typename T> T pwmod(T x, long long n, long long m) {T ret=1;while(n>0){if(n&1)ret=ret*x%m;x=x*x%m;n>>=1;}return ret%m;}
template<typename T> void rsort(vector<T> &v) {sort(all(v), greater<T>());}
template<typename T> bool chmax(T &a,const T& b) {if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,const T& b) {if(a>b){a=b;return true;}return false;}
template<typename T> void fin(const T &a) {cout << a << '\n';exit(0);}
template<typename T, typename S> pair<T, S> mp(const T &a, const S &b){return make_pair(a, b);}
template<typename T> void unique(vector<T> &a){sort(all(a)); a.erase(std::unique(a.begin(), a.end()), a.end());}
template<typename T> vector<int> compress(vector<T> &a){
    int n = a.size(); vector<int> ret(n); vector<T> temp = a; unique(a);
    for(int i = 0; i < n; i++) ret[i] = lower_bound(a.begin(), a.end(), temp[i]) - a.begin();
    return ret;
}
std::ostream &operator<<(std::ostream& os, const modint1000000007 &m){
    os << m.val();
    return os;
}
std::ostream &operator<<(std::ostream& os, const modint998244353 &m){
    os << m.val();
    return os;
}
template<typename T, typename S>
std::ostream &operator<<(std::ostream& os, const pair<T, S> &p){
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
std::ostream &operator<<(std::ostream& os, const vector<T> &v){
    int n = v.size();
    os << "[";
    for(int i = 0; i < n; i++){
        if(i == n - 1) os << v[i];
        else os << v[i] << ", ";
    }
    os << "]";
    return os;
}
template <typename T, typename S>
std::ostream &operator<<(std::ostream& os, const map<T, S> &mp){
    for(auto iter = mp.begin(); iter != mp.end(); iter++){
        os << "(" << iter->first << ", " << iter->second << ")" << " ";
    }
    return os;
}
template <typename T>
std::ostream &operator<<(std::ostream& os, const set<T> &s){
    os << "{";
    for(auto c : s) os << c << " ";
    os << "}";
    return os;
}
#define LOCAL
#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dump(x) true
#endif

//using mint = modint1000000007;
//using mint = modint998244353;

template <typename T>
vector<long long> is_prime(T n){ //n以下の非負整数についてエラトステネスの篩を実行する
    assert(n >= 1);
    vector<long long> ret(n+1, 1);
    ret[0] = 0;
    ret[1] = 0;
    for(ll i = 2; i * i <= n; i++){
        if(!ret[i]) continue;
        for(ll j = i * i; j <= n; j += i) ret[j] = 0;
    }
    return ret;
}

template <typename T>
vector<T> prime_list(T n){ //n以下の素数のリストを返す
    vector<long long> v = is_prime(n);
    vector<T> ret;
    rep(i,n+1) if(v[i]) ret.push_back(i);
    return ret;
}

template <typename T>
vector<T> divisor(T n){ //nの約数を昇順に並べたvectorを返す
    vector<long long> ret;
    for(ll i = 1; i * i <= n; i++){
        if(n%i == 0){
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

template <typename T>
vector<pair<T, T>> prime_factor(T n) { //nの素因数と指数のペアのvectorを返す
    vector<pair<T, T>> ret;
    for (T i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        T tmp = 0;
        while (n % i == 0) {
            tmp++;
            n /= i;
        }
        ret.pb(i, tmp);
    }
    if (n != 1) ret.pb(n, 1);
    return ret;
}

template <typename T>
vector<T> smallest_factor(T n){
    vector<T> ret(n+1);
    rep(i,n+1) ret[i] = i;
    for(T i = 2; i * i <= n; i++){
        if(ret[i] == i){
            for(T j = i * i; j <= n; j += i){
                if(ret[j] == j) ret[j] = j;
            }
        }
    }
    return ret;
}

void solve(){
    ll l, r; cin >> l >> r;
    vl sq;
    auto prime = prime_list(1000010);
    for(auto t: prime){
        sq.pb(t * t);
        if(t * t > 1000010) break;
    }
    vl chk(r-l+1, 1); // l+iが素数かどうか
    for(auto t : sq){
        ll s = div_ceil(l, t) * t;
        for(;s <= r; s += t){
            chk[s-l] = 0;
        }
    }
    cout << SUM(chk) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);

    solve();

    return 0;
}
0