結果

問題 No.1653 Squarefree
ユーザー asayiaasayia
提出日時 2021-08-21 11:02:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,494 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 163,916 KB
実行使用メモリ 27,572 KB
最終ジャッジ日時 2024-04-23 02:49:30
合計ジャッジ時間 8,204 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 <bits/stdc++.h>
#define maxx(a, b, c) max(max(a, b), c)
#define minn(a, b, c) min(min(a, b), c)
#define between(x, l, r) (x >= l && x <= r)
#define point(a, b) ((a - 1) * m + b)
#define y second
#define x first

using namespace std;

const int N = 1000010;

typedef long long LL;

int primes[N], cnt;
bool st[N], check[N];
LL p[N];

void get_primes(int n)  // 线性筛质数
{
    for (int i = 2; i <= n; i ++ )
    {
        if (!st[i]) primes[cnt ++ ] = i;
        for (int j = 0; primes[j] <= n / i; j ++ )
        {
            st[primes[j] * i] = true;
            if (i % primes[j] == 0) break;
        }
    }
}

int main()
{
    LL l, r;
    cin >> l >> r;
    LL d = pow(r, 1.0 / 3) + 1;
    
    // 筛根号三次内的数
    get_primes(d);
    for (int i = 0; i <= r - l; i ++ ) p[i] = l + i;
    
    int res = r - l + 1;
    for (int i = 0; i < cnt; i ++ )
    {
        LL k = ceil(l * 1.0 / primes[i]);
        LL start = k * primes[i] - l;
        for (int j = start; j <= r - l; j += primes[i])
        {
            int tmp = 0;
            while (p[j] % primes[i] == 0)
            {
                p[j] /= primes[i];
                tmp ++ ;
            }
            if(tmp >= 2 && !check[j]) check[j] = 1, res -- ;
        }
    }
    
    for (int i = 0; i <= r - l; i ++ )
    {
        if(check[i] || p[i] == 1) continue;
        LL k = sqrt(p[i]);
        if(k * k == p[i]) res -- ;
    }
    
    cout << res << '\n';
    
    return 0;
}

/*
4 8 9 12
*/
0