結果

問題 No.1653 Squarefree
ユーザー asayiaasayia
提出日時 2021-08-21 11:52:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 163,736 KB
実行使用メモリ 22,464 KB
最終ジャッジ日時 2024-04-23 03:41:05
合計ジャッジ時間 6,283 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
21,236 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 86 ms
19,536 KB
testcase_12 AC 83 ms
19,408 KB
testcase_13 AC 145 ms
22,464 KB
testcase_14 AC 149 ms
20,864 KB
testcase_15 AC 153 ms
20,864 KB
testcase_16 AC 149 ms
20,992 KB
testcase_17 AC 145 ms
20,868 KB
testcase_18 AC 152 ms
20,988 KB
testcase_19 AC 152 ms
20,992 KB
testcase_20 AC 154 ms
20,996 KB
testcase_21 AC 148 ms
22,404 KB
testcase_22 AC 144 ms
21,120 KB
testcase_23 AC 142 ms
21,120 KB
testcase_24 AC 148 ms
20,984 KB
testcase_25 AC 145 ms
20,992 KB
testcase_26 AC 146 ms
21,120 KB
testcase_27 AC 145 ms
20,864 KB
testcase_28 AC 152 ms
20,912 KB
testcase_29 AC 148 ms
20,868 KB
testcase_30 AC 150 ms
20,992 KB
testcase_31 AC 148 ms
20,992 KB
testcase_32 AC 156 ms
21,120 KB
testcase_33 AC 151 ms
20,864 KB
testcase_34 AC 149 ms
20,740 KB
testcase_35 AC 146 ms
20,736 KB
testcase_36 AC 18 ms
7,552 KB
testcase_37 AC 18 ms
7,552 KB
testcase_38 AC 20 ms
7,548 KB
testcase_39 AC 18 ms
7,424 KB
testcase_40 AC 18 ms
7,420 KB
権限があれば一括ダウンロードができます

ソースコード

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;

LL primes[N], cnt;
bool st[N];
LL p[N], check[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;
        }
    }
}

signed main()
{
    LL l, r;
    cin >> l >> r;
    //auto now = clock();
    LL d = pow(r, 1.0 / 3) + 2;
    // 筛根号三次内的数
    get_primes(d); // O(n)
    for (int i = 0; i <= r - l; i ++ ) p[i] = l + i; // O(n)

    int res = r - l + 1;
    for (int i = 0; i < cnt; i ++ ) // O(nloglogn * logn)
    {
        LL start = (primes[i] - l % primes[i]) % primes[i];
        //if(i == 1) cout << start << '\n';
        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;
}

/*
607148
*/
0